Gabe
unread,Sep 27, 2011, 8:38:57 AM9/27/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to iPhone Wax
Is there a way to get wax to release globals?
I have some game objects that have a short script associated with
them. The scripts interact with Objective-C object instances. The
way I have it setup, the Objective-C objects are set as Lua globals.
However, this retains them, so they are not released later. And I
cannot figure how to encourage Wax to release globals.
For example:
//map ObjC objects into Lua
wax_fromInstance(luaState, enemy); //performs a retain :(
lua_setglobal(luaState, "enemy");
wax_fromInstance(luaState, enemyTarget); //performs a retain :(
lua_setglobal(luaState, "target");
wax_fromInstance(luaState, gameState); //performs a retain :(
lua_setglobal(luaState, "gameState");
wax_fromInstance(luaState, currentPlayer); //performs a retain :(
lua_setglobal(luaState, "player");
//run the script
luaL_loadstring(luaState, [[NSString stringWithFormat:
@"functionHitTest() %@ end; didEnemyHit = HitTest()", script]
UTF8String]);
int s = lua_pcall(luaState, 0, 0, 0);
if (s != 0) DebugLog(@"s != 0: %@", script);
report_errors(luaState, s);
//capture results
BOOL didEnemyHit;
lua_getglobal(luaState, "didEnemyHit");
didEnemyHit = lua_toboolean(luaState,1); //extracts the value, leaves
stack unchanged
lua_pop(luaState,1); //pop the value to leave stack balanced
An example script:
NSString *script = @"return enemy:GetSpeed() > target:GetSpeed();";