frankodwyer
frankodwyer

Reputation: 14048

Suggestions for an embeddable scripting language for iPhone and Java app?

I'm developing an app for iPhone with a Java desktop companion that it synchs to over the network. I'd like to embed a scripting language into both apps so that end users can write scripts that add new behaviours and interact with the object model, and so that I can more rapidly develop some features.

Any suggestions for this, or anyone done this before and got experiences to share? I'm thinking of something like tcl which I've used in the past, but not tcl itself as I'm not a big fan of the language.

Main criteria are that it should be

My initial hunch is that I should be using one of python, ruby, or lua. My preference would be ruby, as I already have some experience with it and don't know much about the others. However my main unknown is which of these is easiest to get integrated with iPhone and Java.

edit 2: per Jason Coco in the comments, the SDK terms prohibit embedded scripting languages. Checking into this it does indeed seem to, but I read it to preclude dynamic installation and extension only. I would still be interested in answers here, as the agreement doesn't seem to preclude having prepackaged scripts inside the application bundle itself - Apple would still get to vet that code.

The agreement also seems to allow use of Apples "interpreters"...what are these? Javascript and what else? Any route to use those here?

Upvotes: 5

Views: 4156

Answers (3)

JoeS
JoeS

Reputation: 133

I was researching this too, and it seems that it's possible to pre-compile a Lua script (by converting it to C using Lua and then compiling the C file). Because all of your code could then be part of the application bundle (including the embedded Lua interpreter), it should be acceptable as an iPhone app.

See here for a discussion and sample script: http://lua-users.org/lists/lua-l/2008-11/msg00453.html

*Note that I haven't tried this (yet)

Upvotes: 1

Vihung
Vihung

Reputation: 13397

JavaScript

As I understand the iPhone SDK Licence, there is nothing preventing you from using a scripting language in your app - just that you cannot intall any interpreters or runtimes of your own. You can only use those scripting languages for which Apple provides the interpreter in the SDK.

Given that you want to run the same scripts in your iPhone app and in a Java app, the obvious choice is JavaScript. You can use Apple's APIs in your iPhone app, and something like Rhino (http://www.mozilla.org/rhino/) in your Java App.

You have to be aware that there may be slight differences between the two interpreters in the more obscure regions of syntax or object model.

P.S. I assume that users are going to be writing their own scripts to run on their own device/desktop. These would be part of the application data, and should be fine under Apple's licence

Upvotes: 2

Adam Byram
Adam Byram

Reputation: 1422

The only thing I've seen that allows a non-objective-c/c/c++ application to run on the iPhone is Unity3d (http://unity3d.com/unity/features/iphone-publishing) - BUT, it uses C# via Mono and does a full static compilation (http://tirania.org/blog/archive/2008/Nov-05.html) down to native code in order to do it. So, by the time the app is on the phone, it's no longer C# so it's allowed by Apple (and several apps have already made it into the App Store - so this does seem to be acceptable).

I don't think you would be able to do the idea you're talking about even if you could do the equivalent for Java/Ruby/Lua/Python/other (so having your desktop app pre-compile and upload just the native code to the device). As far as I know, you can't execute code outside of your application bundle...and if you modify the application bundle, then you invalidate the codesigning Apple does which allows the app to run on your phone in the first place. So even if you could get executable code to the phone, I'm not sure that you would be able to run it if it didn't come along with the app in the first place.

Upvotes: 1

Related Questions