I'm trying to get to grips with how Lua works, and how it can be integrated into a project, like an Obj-C based iPhone game. I've got Lua's source integrated fine, and have managed to use a simple manager class to translate function calls written in a .lua file, to Obj-C methods in the project.
I'm now a little stuck; I'm not sure how to go about what I'd like to use Lua for, and having Googled a lot on it I haven't found an article which fills the little gaps in my understanding. What I'd like to do is use Lua to script simple game logic for levels in my game; for example, I might want to check that the player has moved to a certain part of the level, then once he does that I check if he picks up an object, then once he throws that object I check if it hits another object, etc, etc.
In the script, I'd like to have something like this:
if (objectsAreTouching(level.objects["objIndex1"], level.objects["objIndex2"]))
{
//Move to next win-condition.
}
So I know how to access a function, for example the one named above, objectsAreTouching
, but I can't see how I would, from within the .lua file, access a Dictionary or Array from within one of the game's main classes. I assume this must be possible, am I right? If so, how do you do this? If you can, can you then have a method in your game engine which returns a BOOL pass that return value to the script, so that the if statement above would then execute the code within it?
I may well have asked this question badly, and so if I need to clarify anything let me know. Also, I'm aware of the issues surrounding Apple's ban of interpreted code, and it doesn't concern me for this little project.
Thanks for any help!