lua-users home
lua-l archive

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


On Thu, May 20, 2010 at 18:15, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
Not necessarily. If the function is a main function (that is, the direct
result of load) then _ENV is always the first (and only) upvalue and it
is always present. Other functions have _ENV just like any other upvalue.
For instance, consider the following code:

 local a
 function foo ()
   return a + b
 end

In function foo, the first upvalue is 'a' and the second is '_ENV'.

Why isn't it always the first upvalue? It would make things easier if one wants to play with the environment...

-- Pierre-Yves