开发者

Which script language interpreters will work on iOS?

开发者 https://www.devze.com 2023-01-08 22:48 出处:网络
For an App that is not going to be released on the AppStore I\'m looking to embed an interpreter for easy scripting needs. Since I don\'t really like to get down with pure C, the interpreter should be

For an App that is not going to be released on the AppStore I'm looking to embed an interpreter for easy scripting needs. Since I don't really like to get down with pure C, the interpreter should be an Objective C library.

开发者_C百科

While searching the web I've come across a couple of script interpreters for Objective C but whether those guys work on iPhone is not quite so clear. The one I found that apparently works well on iPhone is LuaCore which brings Lua scripting to iOS Apps.

Which Objective C scripting interpreters have you successfully embedded in iOS Apps?


Some Javascript options:

  1. Using a headless WebKit instance
  2. Instantiate a custom build of JavaScriptCore
  3. CouchBase's attempt at getting SpiderMonkey running (more modern Javascript than V8)

Notice that the JS option will provide with a quite raw runtime environment, you'll probably need to write at least some of it yourself for it to be a convenient development environment.

Other languages:

  1. An attempt with Python.
  2. Clojure by way of a static build of JavaScriptCore (see point 2 above).
  3. The Nu language is also supposed to integrate well, and have a good Objective-C bridge.

I have only tried the first headless WebKit variant for Javascript, but plan to try as many of those listed as possible for a project during the coming months.

Update: I've used the Javascript method 1 (headless WebKit) a bit longer. I got it running quite effortlessly, and will stick with that for a while. But it has a huge drawback: you can't call back to native in an easy manner. I solved this by writing a PhoneGap inspired bridge that empties a command queue after the script has run.

I've also tried Python using the link I gave. I made it compile and execute some sample code, but it suffers from the same problem as using Js via headless WebKit, and since it consumes quite a bit of memory I skipped it for now. A callback command queue in the same spirit as the one I created with Js would be possible though. Another Python method would be to attempt to call into the Objective C runtime using ctypes. That approach is described in this answer.

Update 2: Here are several new(ish) links for running Scheme, with both interpreter and compilation options.


I just stumbled upon a really decent description by Twitter user @mysterycoconut of how to get Lua support up and running.


Just discovered a post regarding scripting on iOS at answerspice.com.

Based on the post I evaluated Nu and had it up and running pretty quickly based on the Xcode project referenced in this discussion (thanks Tim!). I tested in the simulator and on an iPhone 4. So Nu is definitely among the scripting languages that can be embedded in an iOS App.

0

精彩评论

暂无评论...
验证码 换一张
取 消