What is the big deal with Lua switching from setfenv() to _ENV?
In various "What's New" sources, this move is mentioned as one of the most important changes between Lua versions 5.1 and 5.2.
However, the examples given in PIL and elsewhere can be trimmed to the following:
-- Lua 5.1 -- Lua 5.2
function myfunc() function myfunc()
setfenv(1, {}) _ENV = {}
end end
So far, what we gained here is we have saved five key strokes. (I believe the situation is not much different from the C side.) Moreover, if I got it right, setfenv() can be used both from the outside and from the inside of a function, whereas _ENV can be accessed only from the inside of a function. (Of course, when using the C API, one can access the upvalues directly.) From what I wrote, the 5.2 approach seems much less flexible.
In his The Novelties of Lua 5.2, Roberto writes:
"Being a syntactic sugar, it is much simpler than the old environments"
Where's the simplicity? What have I overlooked?
I believe this topic is worth better treatment that it is given in the 5.2 User Manual.