lua-users home
lua-l archive

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


Leo Razoumov wrote:
> I would like to use lua_setglobal and lua_getglobal. These functions
> use LUA_GLOBALSINDEX. 

These are macros. Redefine them to do what you want:

#undef lua_setglobal
#undef lua_getglobal
#define lua_setglobal(L,s) lua_setfield(L, LUA_ENVIRONINDEX, (s))
#define lua_getglobal(L,s) lua_getfield(L, LUA_ENVIRONINDEX, (s))

Or you can have two versions for thread globals and function globals:

#define lua_settglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
#define lua_gettglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
#define lua_setfglobal(L,s) lua_setfield(L, LUA_ENVIRONINDEX, (s))
#define lua_getfglobal(L,s) lua_getfield(L, LUA_ENVIRONINDEX, (s))