moai/moai-dev — pull request #776 by patrickmeehan (2013-09-09 19:49:32+00:00)
Title: Fix/lua gc

I cleaned up the smart pointer semantics a bit and renamed some things to clarify intent. 'MOAILuaLocal' is now 'MOAILuaMemberRef.' I also got rid of MOAILuaObject's GetLocal, SetLocal, PushLocal in favor of the smart pointer. Now all of the Lua smart pointers have a similar interface and usage.

Also also removed the MOAILuaRefTable implementation. Not sure why it was needed in the first place. Now the ref two tables are just a weak and strong table help in Lua's registry and managed with luaL_ref and luaL_unref.

Most importantly, I fixed a crash that would happen when an object's Lua binding would get GC's but member refs remain. The actual crash was an assert () on mMemberTable triggered by a false positive when testing the validity of a member ref and attempting to push the member table.

I've run our game with this and some of the samples, but haven't tested exhaustively. Would definitely appreciate extra eyes on this, particularly the move from MOAILuaRefTable to luaL_ref and luaL_unref.