lua-users home
lua-l archive

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

On 04/05/16 01:50 AM, Duane Leslie wrote:
This is nice and all, but ever heard of loadx[1]?

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.
Without exposing the debug library. (read: sandbox-safe)

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`

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)



Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.