lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Mon, Oct 12, 2009 at 3:48 PM, Duncan Cross <> 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)) {
   MyObject** new_wrapped_ptr = (MyObject**)lua_newuserdata(L,
   *new_wrapped_ptr = myObject;
   lua_pushlightuserdata(L, (void*)myObject);
   lua_pushvalue(L, -2);
   lua_settable(L, LUA_REGISTRYINDEX);