Releasing Globals

17 views
Skip to first unread message

Gabe

unread,
Sep 27, 2011, 8:38:57 AM9/27/11
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();";
Reply all
Reply to author
Forward
0 new messages