lua-users home
lua-l archive

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


Scanning the Lua documentation,

would it be as easy as creating a new table,  and setting it as the
environment via

lua_setfenv

then as you mentioned setting this new table's __index key to the
LUA_GLOBALSINDEX table, will make the new environment fall-back on the
original globals table (if somthing doesnt exist, for instance?)

when new variables are created in a script with this modification will
they be saved in the new table?

On 1/19/07, Rici Lake <lua@ricilake.net> wrote:

On 19-Jan-07, at 10:29 PM, Raymond Jacobs wrote:

> This is now slightly off-topic, but
>
> I don't suppose there is a way to identify 'system' tables, such as
> os,_G,math, and etc.?

Nope. There's no such thing as a system table, really: the Lua core
doesn't define any; they're all inserted by the embedding application.

If you're trying to maintain some sort of additional environment, I'd
suggest you use an environment table; you can give it {__index = _G} as
a metatable which will make the initial globals table the fallback.
lua_next ignores metatables, so it will only iterate over keys that are
actually in the table you're iterating.