[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua 5.2 beta: trap with lua_getglobal
- From: Patrick Rapin <toupie300@...>
- Date: Sat, 22 Oct 2011 13:55:24 +0200
I just had a crash with Lua 5.2 and it took me a little to understand why.
The problem is with the following instruction:
lua_getglobal(L, lua_tostring(L, -1));
With Lua 5.1, this is no problem. The macro expands to
lua_getfield(L, LUA_GLOBALSINDEX, lua_tostring(L, -1))
But on Lua 5.2, the macro now expands to:
(lua_pushglobaltable(L), lua_getfield(L, -1, ( lua_tostring(L,
-1))), lua_remove(L, -2))
And when the lua_tostring is evaluated, the stack has changed !
I propose to rewrite the macro with something like:
#define lua_getglobal(L,s) \
do { const char* S=s; lua_pushglobaltable(L); lua_getfield(L, -1, S);
lua_remove(L, -2); } while(0)