lua-users home
lua-l archive

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


> In the reference manual, §6.1:
> 
> >If the resulting function has upvalues, the first upvalue is set to the value of env, if that parameter is given, or to the value of the global environment. (When you load a main chunk, the resulting function will always have exactly one upvalue, the _ENV variable (see §2.2). However, when you load a binary chunk created from a function (see string.dump), the resulting function can have arbitrary upvalues.)
> 
> The last sentence states that load() can be used for binary chunks and they can have arbitrary upvalues. However the implementation does not follow this.

Both dump and load work with any function, with any number of upvalues.
However, dump does not save (and therefore load cannot restore) the
values of those upvalues, as that would involve a complete data
serialization system way out of the scope of Lua. So, when load
restores a function with upvalues, its upvalues are instanciated
with fresh instances containing nil. Programmers can use
functions like lua_upvalueid and lua_upvaluejoin to save/restore
upvalues when necessary. We will clarify the manual.

-- Roberto