lua-users home
lua-l archive

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


>   Associated with any lua_State *L is an environment.
> 
>   This environment can be observed or replace by using lua_pushvalue
>   or lua_replace with LUA_ENVIRONINDEX.

Not exactly. Every C function has its own environment (like Lua functions).
This is what you observe in LUA_ENVIRONINDEX. (You may think about the
environment as a kind of dynamic component of each closure.)


> All this I understand.  What I don't understand is this: when 
> I call lua_replace(L, LUA_ENVIRONINDEX), which *functions'*
> environments are changed?  Is it only the youngest active function
> called with lua_call, or can other functions' environments change, too?

Only of the running function; exactly as when you call "setfenv(1, f)" from
Lua.


> Here's the $64 question: can any caller of foo observe whether foo
> contains a call to lua_replace(L, LUA_ENVIRONINDEX)?

Indirectly. you can get 'foo' current environment (the one that will
be changed by its call to lua_replace) by calling lua_getfenv.

-- Roberto