On Mon, Oct 12, 2009 at 3:48 PM, Duncan Cross <
duncan.cross@gmail.com> wrote:
> This is a simplified example of how you generally want
> to handle using light and full userdata together:
Sorry, I messed this code up a bit, let me try again:
void PushMyObject(lua_State* L, MyObject* myObject) {
lua_pushlightuserdata(L, (void*)myObject);
lua_gettable(L, LUA_REGISTRYINDEX);
if (lua_isnil(L,-1)) {
lua_pop(L,1);
MyObject** new_wrapped_ptr = (MyObject**)lua_newuserdata(L,
sizeof(myObject*));
*new_wrapped_ptr = myObject;
lua_pushlightuserdata(L, (void*)myObject);
lua_pushvalue(L, -2);
lua_settable(L, LUA_REGISTRYINDEX);
}
}
-Duncan