[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Declared UpValues, change to Parser.
- From: Duane Leslie <parakleta@...>
- Date: Wed, 4 May 2016 14:50:30 +1000
> This is nice and all, but ever heard of loadx?
> : 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`
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)