lua-users home
lua-l archive

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




2013/1/25 Peter Cawley <lua@corsix.org>
This behaviour, along with the reason for it, is explicitly documented in 5.2 manual entry for load:
    
    If the resulting function has upvalues, the first upvalue is set to the value of the global environment or to env, if that parameter is given. When loading main chunks, the first upvalue will be the _ENV variable (see §2.2).

Lanes uses dump/undump to transfer functions from a state to another, and I noticed that _ENV is not always the first upvalue. It is just a matter of when the first 'global' lookup is done by the function.
Running the attached script you'll notice that _ENV is not the first upvalue. In this case it happens after referencing another upvalue, so it comes second.

Should the manual be amended?

--
Benoit.

Attachment: upvals.lua
Description: Binary data