lua-users home
lua-l archive

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


> This is nice and all, but ever heard of loadx[1]?
>
> [1]: https://github.com/SoniEx2/loadx

I hadn't heard of loadx, but it doesn't solve the same problem.  I'm
not clear exactly on what loadx does that isn't achievable with the
existing debug functions, but it seems that it just provides a
convenience method for binding upvalues when loading a function.

The point of the changes I made was to declare the order and legality
of upvalues at the point of parsing Lua code.

To demonstrate, take the example from the loadx README:

local fc2 = string.dump(function() print(UP1[UP2]) end) -- function code 2
local fc3 = string.dump(function() local val = UP1[UP2]; print(val)
end) -- function code 3

These two functions (`fc2` from the README, `fc3` as my modified
version) access the same upvalues but in a different order and so
loadx will fail to return the correctly bound function in the `fc3`
case.

My proposal is to have identical upvalues and ordering regardless of
the function body.

local fc4 = string.dump(function () <_ENV,UP1,UP2> print(UP1[UP2]) end)
local fc5 = string.dump(function () <_ENV,UP1,UP2> local val =
UP1[UP2]; print(val) end)

Regards,

Duane.