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.