I haven't used Lua in about 8 months (or more), so I'm trying to refresh my mind, while at the same time migrating to 5.2 from 5.1.
In a function I wrote way back then, I iterate over a table recursively descending into sub-tables, starting at the global index.
I used the global 'LUA_GLOBALSINDEX' which is no longer available in 5.2. What can I use instead?
For example, if I want to call: lua_type(luaState, LUA_GLOBALSINDEX);
...to get the type of the global table itself (LUA_TTABLE, right?), how can I do that with Lua 5.2?
Would: lua_pushglobaltable(luaState);
int globalIndex = lua_tointeger(luaState, -1);
I don't use Lua 5.2, but try lua_getglobal
It is my understanding that macro is still available and has been redefined to behave the same way as it did in 5.1
Doesn't that get a specific global, like:
lua_getglobal(lua, "MyGlobalVariable")
I want to get the table that all the global variables are stored in. That is to say, I want to get the table that is the parent of "MyGlobalVariable", not "MyGlobalVariable" itself.How can I do that?
'_G' is the global table that holds everything. lua_getglobal(lua, "_G") should do the trick.
Apparently Lua 5.2 introduces "environments", so you should check the variable '_ENV' as well.
Beware _G is recursive, therefore _G contains _G as well.
[color=#000000][font=Helvetica, Arial, sans-serif]A global variable (not a function) that holds the global environment (see [/font]§2.2[color=#000000][font=Helvetica, Arial, sans-serif]). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa.[/font]
[/quote]
Does this mean when I add values to the global environment, _G is not updated to reflect the changes?
Also, "LUA_RIDX_GLOBALS: At this index the registry has the global environment."
Would that mean LUA_RIDX_GLOBALS functions the same as LUA_GLOBALSINDEX used to?
I mean, does this hold true: ([size=2]I'm not capable of testing it at the moment)
lua_pushglobaltable(luaState);
int globalIndex = lua_tointeger(luaState, -1);