Dave Newman

Posts tagged cocos2d

3 notes &

Write your cocos2d game in Lua!

Yep, screw objective-c. With iPhone Wax it’s now super easy to get Lua going in your IOS apps. I’m going to write more about how this works in the future, but right now I’m just going to link to my example app on github.

http://github.com/snappycode/cocowax

Here are the interesting parts:

main.m

wax_startWithExtensions(luaopen_wax_http, luaopen_wax_json, luaopen_wax_xml, nil);

Starts up the wax Lua environment. Also loads a few extensions.

data/scripts/LuaScene.lua

waxClass{ "LuaScene", CCScene }
function init(self)
  ...
end

This is where the actual Scene is created in Lua. waxClass creates “LuaScene” as both a Lua object and an objective-c class.

cocowaxAppDelegate.m

[[CCDirector sharedDirector] runWithScene: 
  [[[NSClassFromString(@"LuaScene") alloc] init] autorelease]];     

Creates the instance of the lua scene in objective-c and runs it as normal.

copy-scripts.sh

Copies the data directory with all the Lua scripts into the application bundle.

Happy hacking!

Filed under lua cocos2d