5

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.

fbrereto
  • 35,429
  • 19
  • 126
  • 178
Fabrizio Farinelli
  • 241
  • 1
  • 4
  • 8
  • Are you sure that it's possible? IIRC Apple forbids the use of interpreted languages on the iPhone. – Timo Geusch Apr 06 '10 at 16:07
  • 1
    @Timo Geusch: Not true. (As has already been discussed multiple times here on SO.) The only thing that is forbidden is loading code from untrusted sources like the network or the user. If your code comes from a *trusted* source (which basically means the App Store), Apple doesn't care how you run it: interpret it, compile it, heck, send it to China to be hand-evaluated by child-slaves. There's plenty of interpreted code in the App Store, e.g. the Wikipedia App which is written in Ruby. – Jörg W Mittag Apr 06 '10 at 17:46
  • 3
    If you can't find the Lua documentation then you probably aren't in a position to be writing much software. – Azeem.Butt Apr 06 '10 at 23:53
  • 1
    Of course, as of yesterday, all of this has changed. With the *new* 4.0 Agreement, *only* C, C++, Objective-C and JavaScript are allowed. It's not even allowed to use another language and *generate* one of those, applications must be *originally written* in one of those four. – Jörg W Mittag Apr 11 '10 at 10:12
  • 1
    related: http://stackoverflow.com/questions/1209771/2d-lua-games-on-iphone – cregox Jan 12 '11 at 19:19
  • possible duplicate: http://stackoverflow.com/questions/937136/lua-on-iphone – cregox Jan 12 '11 at 19:19
  • I answered to a related question, maybe it helps?! Here's the [link][1] [1]: http://stackoverflow.com/questions/2823964/how-to-embed-iphone-wax-into-app/7940252#7940252 – Florin Oct 29 '11 at 16:54

4 Answers4

7

Check out the Corona SDK.

lhf
  • 70,581
  • 9
  • 108
  • 149
4

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
  • 60,510
  • 8
  • 78
  • 126
  • 1
    Apparently the restrictions have been removed. See http://www.apple.com/pr/library/2010/09/09statement.html – lhf Sep 09 '10 at 13:36
  • 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 Sep 09 '10 at 15:54
4

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

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
3

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 Van Brunt
  • 15,244
  • 11
  • 66
  • 92