lua-users home
lua-l archive

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


I've been wanting to make a separate environment for a while now, but
I don't quite understand what it's all about.

e.g. I'd like variables I declare in script to be globally accessible
(in the globals table I guess) but having it separate from all the
other stuff would be nice.

I really have no idea how to set all of that up from the C API though =/

-Raymond

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.