[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: does the current environment revert automatically?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 23 Dec 2007 13:00:59 -0200
> 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