Skip to content

Commit

Permalink
Lua 5.2: use new macro lua_pushglobaltable
Browse files Browse the repository at this point in the history
This macro is not mentioned in the Lua 5.2 manual.
  • Loading branch information
Peter Colberg authored and Daniel Wallin committed Jan 18, 2012
1 parent 3866d4c commit 8c66030
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 3 additions & 5 deletions luabind/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1214,11 +1215,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));
}
Expand Down Expand Up @@ -1422,6 +1419,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
Expand Down
10 changes: 5 additions & 5 deletions src/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <luabind/detail/stack_utils.hpp>
#include <cassert>

#if LUA_VERSION_NUM < 502
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#endif

namespace luabind { namespace detail {

registration::registration()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8c66030

Please sign in to comment.