[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: does the current environment revert automatically?
From:       Roberto Ierusalimschy <roberto () inf ! puc-rio ! br>
Date:       2007-12-23 15:00:59
Message-ID: 20071223150059.GA16983 () inf ! puc-rio ! br
[Download RAW message or body]

>   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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic