views:

245

answers:

4
+1  Q: 

Lua on the iPhone

I'm trying to load at run-time Lua scripts on the iPhone. Is there a possibility to do that?

How can I getting started with Lua? I can't find something. The only thing I can find is that this should be possible, but I am wondering how.

+3  A: 

the Lua docs are very good, also read PIL (Programming in Lua) first edition is available online, the second edition is inexpensive on hard copy.

Lua is specifically designed to be used as an embedded language, simply link to any C (or Obj-C, or C++) project, and use the C API to load scripts and run them.

Note that Apple forbids to create scripting platforms; but AFAICT, that only means that the user shouldn't be able to add Lua scripts to enhance your app. You're free to use embedded Lua to make your App more flexible and easier to write.

Javier
Apparently the restrictions have been removed. See http://www.apple.com/pr/library/2010/09/09statement.html
lhf
As I read it, the removed restrictions were only those recently added: those that limited the languages and tools. now the rules are closer to the original: use whatever tool/language you want, but all code must be embedded in the app
Javier
+3  A: 

Check out the Corona SDK.

lhf
It's a bit depressing that the shiny web pages don't even mention the word Lua. Can anyone comment if this is SDK is worth the $99?
Norman Ramsey
+1  A: 

See also iPhone Wax: http://github.com/probablycorey/wax

Alexander Gladysh
+2  A: 

I have compiled Lua into an iPhone app. It is fairly straight forward if you have used Lua in other contexts. The only real gotcha is that the iPhone doesn't expose its file system in a traditional way so I ended up using the resource bundle to store scripts and had to rewrite the lua_dofile function to accept files from the bundle.

I would recommend compiling Lua into a non-iPhone app before attempting to use it on the iPhone. Once you understand the c api shoehorning it into the cocoa mobile framework is not that hard.

Nick