lua-users home
lua-l archive

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


On Sun, Apr 13, 2014 at 10:34 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2014-04-14 3:34 GMT+02:00 Coroutines <coroutines@gmail.com>:
>
>> I'd like to see pack()/unpack() added back for compressing a number of
>> objects on the stack into a userdata and "unpacking" them to where a
>> vararg might be expected.
>>
>> I'd like to see these added in both the C API and exposed as 2 core
>> library functions.
>>
>> My argument is that sometimes it can be weighty to store varargs in a
>> table using table.pack().  Furthermore, it's difficult to do
>> continuation passing style (CPS) without tables (or coroutines):
>> http://codepad.org/eQP2e87S
>
> 1. Should tables be stored as references or are we talking about
> serializing them in the process?
> 2. In terms of implementation, I've been trying to work out how to
> do this more efficiently to a full userdata than to a table.
> No success yet.
>

No serializing tables -- I'm assuming that tables are kept in some
sort of "data portion" in the Lua global_State, and are not pushed
onto the stack in whole whenever you use them -- just references.
>From what I understand, certain objects are pushed by reference while
others are pushed in literal form (booleans & numbers?).  I thought
the virtual Lua stack was engineered to be roughly word-sized, so
objects are either literal or referenced for easy walking of that
stack?  (Maybe I'm wrong?)

What I was thinking was: Literal object or reference, these items on
the stack would be compressed/packed into a userdata -- that
containing userdata would make a GC association to anything it
contains that can be collected.  Unfortunately I don't know how this
could then be lighter than using a table.  If you used setuservalue()
to associate a table referencing all the packed items to the "vararg
userdata" then you're not cutting out the waste of the table.

-- BUT if Lua's GC can tell which references are dead/collected
objects then you can simply pack the items on the stack into a
userdata and unpack them later without worry of using an invalid
reference.