lua-users home
lua-l archive

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


On 11/27/18, Sean Conner <sean@conman.org> wrote:
>   I think there's a bug in the description for string.dump().  It states,
> "[w]hen (re)loaded, those upvalues receive fresh instances containing nil."
> But load() states "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 an arbitrary number of upvalues."

Sure. When (re)loaded, the dumped function has fresh upvalues that
aren't the same as those or any other function, which are initially
nil. Then load() (and lua_load()) set the first upvalue.

... hm, perhaps load setting the first upvalue of functions that
aren't main chunks (linenumber != 0) just doesn't make much sense in
the first place? Or if the incompatibility there seems gratuitous
(maybe it can go into 5.4?), indeed, mention the first upvalue in the
description of string.dump.

Initially I expected lua_load to not set the first upvalue, but that
doesn't seem to be the case.