views:

346

answers:

2

My app needs to use a library which is only available for Python and Ruby. From my understanding, Apple allows Ruby to run on iPhone as long as users can't execute arbitrary code (Rhomobile uses Ruby).

How can I bundle Ruby/Python with my app, call a function from my Obj-C code, and get the result (a string) back in C or Obj-C format?

+2  A: 

You can't. The new SDK agreement prohibits using original languages other than C, C++, or Objective-C, and the SDK agreement has always prohibited dynamically interpreting code. There's some ambiguity about how these rules will be enforced, but to be safe, it's best to avoid other languages until the kinks get worked out.

EDIT: In addition, as far as I know, there's no current technical way to run Python on the iPhone, as per this question. I've heard of embedding Lua in iPhone apps, but not Python. You can do Python with a jailbroken iPhone, but not through the app store.

The Ruby situation is almost as bad, as per this question. The iPhone doesn't ship with a Ruby interpreter, and compilers are a long ways off from working. Rhomobile works by packaging an interpreter and framework with the executable, which I highly doubt will make it past the new SDK agreement. If you really want to use Ruby, Rhomobile would probably be the best bet (as implementing your own interpreter would probably be a lot of work, and equally as unlikely to be approved). It's a rather depressing landscape at the moment--the most we can hope for is that MacRuby will eventually work, and Apple will approve it. That's a long ways off, though.

EDIT 2: I also just found out about tinypy, which could potentially work for Python. I doubt it would run real libraries though.

eman
I'm willing to take my chances with Apple; I think they'll let me through. Does anyone know how to do this?
igul222
@igul222, You think wrong.
Mike Graham
Yeah, I expected that comment. I realize it's not ideal by any stretch, but there's truly no C/C++/ObjC alternative (short of doing the processing on a server and sending results back, which requires a network connection). The app would degrade gracefully if something breaks in the future, but the only real alternative is re-writing the library in C, an option so painful (at least for an inexperienced programmer like myself) that I'd at least like to try this route first.
igul222
As per the updated answer, either try rhomobile or tinypy, and see if either work. I doubt tinypy will do what you want or rhomobile will get through the app store, though.
eman
FYI there are many Rhodes-based apps on the App Store including Wikipedia, MyHumana, RhoLogic for SugarCRM, Multilingual, TrackR, and dozens more. Many are out on http://rhomobile.com. We talk with Apple often and take steps to insure ongoing compliance with all iOS terms of service.
Adam Blum
+2  A: 

FYI there are many Rhomobile Rhodes-based apps on the App Store including Wikipedia, MyHumana, RhoLogic for SugarCRM, Multilingual, TrackR, and dozens more. Many are out on http://rhomobile.com. We talk with Apple often and take steps to insure ongoing compliance with all iOS terms of service.

Also strictly speaking what ships with your final native app is not an interpreter but (on all platforms but BlackBerry) a Ruby 1.9 bytecode executor. And true interpretation (eval) is disabled intentionaly.

Adam Blum