Skip to content

Commit

Permalink
get rid of lightuserdata for ValueInRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Apr 17, 2018
1 parent 29f5916 commit e1f55cb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ext/luawrapper/include/LuaContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,24 +1768,24 @@ class LuaContext {
// this constructor will clone and hold the value at the specified index (or by default at the top of the stack) in the registry
ValueInRegistry(lua_State* lua_, int index=-1) : lua{lua_}
{
lua_pushlightuserdata(lua, this);
lua_pushvalue(lua, LUA_REGISTRYINDEX);
lua_pushvalue(lua, -1 + index);
lua_settable(lua, LUA_REGISTRYINDEX);
ref = luaL_ref(lua, -2);
lua_pop(lua, 1);
}

// removing the function from the registry
~ValueInRegistry()
{
lua_pushlightuserdata(lua, this);
lua_pushnil(lua);
lua_settable(lua, LUA_REGISTRYINDEX);
lua_pushvalue(lua, LUA_REGISTRYINDEX);
luaL_unref(lua, -1, ref);
lua_pop(lua, 1);
}

// loads the value and puts it at the top of the stack
PushedObject pop()
{
lua_pushlightuserdata(lua, this);
lua_gettable(lua, LUA_REGISTRYINDEX);
lua_rawgeti(lua, LUA_REGISTRYINDEX, ref);
return PushedObject{lua, 1};
}

Expand All @@ -1794,6 +1794,7 @@ class LuaContext {

private:
lua_State* lua;
int ref;
};

// binds the first parameter of a function object
Expand Down

0 comments on commit e1f55cb

Please sign in to comment.