lua-users home
lua-l archive

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


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)