how easy is it to debug stuff in Lua compared to native code on iPhone?
Of course, you can't run a Lua script step by step using XCode, but what I do is simply forward any error messages to a dialog box which gives info about the script file and line in which the error occured, and when I need to collect and output debug info, I just store it into a string and then print the screen to the dialog box. Question. How is it possible for Lua to compile within XCode? Is it because, like you suggest, the LUA engine is written in Objective-C and then you just run a script within the engine? What if we had like a BlitzMax interpreter which could run BlitzMax code like a run-time script? Maybe wouldn't be fast though.
Lua is written in ANSI-C code, so I only had to add all the Lua source files to my project and fix a bug with it trying to load scripts from the root directory instead of the application bundle.Then, an iPhone application, just like any Cocoa-basedc application, is event driven. When you launch the application, the "main" function (the standard entry point in C programmming) only creates an autorelease poll (it is an object which simply collects garbage in your code and then frees it after the current event has been processed), and enters de UIApplicationMain() function, passing the name of your main class to it. This function is responsible for all the event handling. It first initialises your main class, and calls its "applicationDidFinishLaunching" method (I am quoting from memory, not completely sure that's the exact name). Here you put your initialization code, which in my case is initializing the OpenGL context, initializing Lua (and calling it's "init" script function), and setting up a timer which ticks 25 times per second. Then the function returns control to the event handler, which will call a function every time my timer ticks. In that function, I want to call a "frame" function in my script, which will update all game logic, and then render another frame.
In fact, it is really simple, and works well. If someone writes a BlitzMax-like scripting engine in C, it would work the same way.