diff --git a/luabind/object.hpp b/luabind/object.hpp index ee4f96ed..08bfafe2 100644 --- a/luabind/object.hpp +++ b/luabind/object.hpp @@ -50,6 +50,7 @@ # define LUA_OPEQ lua_equal # define LUA_OPLT lua_lessthan # define lua_rawlen lua_objlen +# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) #endif namespace luabind { @@ -1212,11 +1213,7 @@ inline object newtable(lua_State* interpreter) // this could be optimized by returning a proxy inline object globals(lua_State* interpreter) { -#if LUA_VERSION_NUM >= 502 - lua_rawgeti(interpreter, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); -#else - lua_pushvalue(interpreter, LUA_GLOBALSINDEX); -#endif + lua_pushglobaltable(interpreter); detail::stack_pop pop(interpreter, 1); return object(from_stack(interpreter, -1)); } @@ -1420,6 +1417,7 @@ object property(GetValueWrapper const& get, SetValueWrapper const& set) # undef LUA_OPEQ # undef LUA_OPLT # undef lua_rawlen +# undef lua_pushglobaltable #endif #endif // LUABIND_OBJECT_050419_HPP diff --git a/src/scope.cpp b/src/scope.cpp index 24a94c97..8b0ed9e7 100755 --- a/src/scope.cpp +++ b/src/scope.cpp @@ -29,6 +29,10 @@ #include #include +#if LUA_VERSION_NUM < 502 +# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) +#endif + namespace luabind { namespace detail { registration::registration() @@ -149,11 +153,7 @@ namespace luabind { } else { -#if LUA_VERSION_NUM >= 502 - lua_rawgeti(m_state, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); -#else - lua_pushvalue(m_state, LUA_GLOBALSINDEX); -#endif + lua_pushglobaltable(m_state); } lua_pop_stack guard(m_state);