lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Then, if we have f1 and f2 with the same _ENV upvalue, which is physically kept in upvalue list of f1, setfenv(f1) would be problematic. Since it can't change upvalue reference in f2, it would have to allocate new upvalue somewhere and set a reference to it in f1.


If I am to choose between setfenv and _ENV, I would choose setfenv. I guess shared upvalues may be useful in some situations, but setfenv is surely much more useful.

On 25.05.2010 0:12, Roberto Ierusalimschy wrote:
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.

-- Roberto




--

___________________________________________
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru