lua-users home
lua-l archive

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




On 07/10/15 11:33 AM, Dirk Laurie wrote:
2015-10-07 14:43 GMT+02:00 Soni L. <fakedme@gmail.com>:

On 07/10/15 04:50 AM, Dirk Laurie wrote:
2015-10-07 0:53 GMT+02:00 Soni L. <fakedme@gmail.com>:

loadx is a Lua 5.2 and Lua 5.3 library which provides a better `load()`.
It
currently supports:
...
- You can set ALL the upvalues, not just the first! This, combined with
the
above, makes this library perfect for seriali(s|z)ing and
(de|un)seriali(s|z)ing functions!
Maybe loadx could also return a table of upvalues, with names as
a list and values as a key-value pair, i.e.

f, upvals = loadx(chunk,nil,nil,'foo','bar')
-- upvals = {'a','b',a='foo',b='bar'}

A table of upvalue objects (the ones you get from newupval())?
I did not think of that, no: it's just that lua_setupvalue returns the
function's name for that upvalue, so it is easy to create a table
of actually supplied upvalues keyed by their names. Since the
order may be important, the names are keyed by 1,2,...

This is the table format also used by some XML-to-Lua modules.

But you gave as an example:

{'a','b',a='foo',b='bar'}

Ok, sure, 'a' and 'b' at [1] and [2] are the names. But ['a'] and ['b'] map to the values! Instead of mapping to the values passed, why not map to "upvalue objects"?

Also, what if you don't have any names?

--
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.