[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The removal of function environments: An opportunity for optimization?
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Tue, 25 May 2010 14:42:16 -0300 (BRT)
Hi Roberto
Please, tell me what I've missed in that discussion:
In fact I don't quite understand what _ENV is.
function f1()
return f2()
_ENV = {}
end
end
Would execution of f2 lead to a change in _ENV of f1? If _ENV is a
regular upvalue that may be shared, then it would.
_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?
Regards,
Tomás