lua-users home
lua-l archive

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


> As I understand, every Lua function will have at least one upvalue,
> _ENV.  This would be slot 0 ?

Only the main function of a chunk will have a fixed, single upvalue _ENV
in slot 1. Other functions may or may not have an upvalue _ENV, which
may be in any position, as happens with any upvalue. (It is created on
demand by the compiler.)

I see two strategies for handling binary functions:

- If the function has one single upvalue called _ENV, 'load' will
initialize it with _G (similarly for 'loadin').

- If the function has any upvalue called _ENV, 'load' will initialize it
with _G (similarly for 'loadin').

(Actually, the strategy is the same for text functions, but in that
case the result will surely have just one upvalue, called _ENV.)

-- Roberto