[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The removal of function environments: An opportunity for optimization?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 25 May 2010 14:54:11 -0300
> >_ENV is a regular variable (and so a regular upvalue that may be
> >shared). Then it does.
> I thought it was a "regular local variable", since you defined:
>
> Any chunk is compiled as if surronded by the following code:
> local _ENV = <some value>; function (...) <chunk> end
>
> Thus, I thought the above code (correcting `f2' to `function')
> could be rewritten as:
>
> local _ENV = _ENV -- In Lua 5.1 it could be written `local _ENV = _G'
> function f1()
> local _ENV = _ENV
> return function()
> _ENV = {}
> end
> end
>
> In this case, I think the inner statement would not change f1's _ENV.
> What am I missing?
What gets the surrounding _ENV declaration are *chunks*, not functions.
Everything inside the same chunk (a compilation unit) share the same
_ENV, unless there are explicit declarations of other _ENVs.
-- Roberto