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