[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Declared UpValues, change to Parser.
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 4 May 2016 07:17:51 +0200
2016-05-04 5:47 GMT+02:00 Duane Leslie <email@example.com>:
> I needed a way to specify the upvalues of a function explicitly so
> that I could serialise and de-serialise user defined functions in a
> reliable way. I have added the syntax of an angle bracketed parameter
> list for upvalues which comes after the argument parameter list in the
> function definition.
> For example, the main chunk which was previously defined as:
> function (...)
> is now defined as
> function (...) <_ENV>
You can do that without changing the parser.
All you need to do is to use the upvalues in the
desired order at the start of the function before
referring to anything else. You can even make it look
like a declaration. For example:
local function upvalues(...) end
function f(x,y) upvalues(a,b,c)
will generate a function with a,b,c as upvalues numbered
1,2,3 ('upvalues' being upvalue 0). _ENV only comes in
as upvalue 4.