lua-users home
lua-l archive

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


Simple and sweet:

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

I am aware of the vararg library.  It provides more than I need and
I'd like to see just these 2 abilities added upstream.  Perhaps it's
just a common impulse to want to avoid third-party modules, but there
used to be a lot of talk on the lua-users wiki about making varargs a
"first-class citizen" -- maybe this could be the compromise?

How about a discussion for or against?

I want this but here are 2 reasons not to have this:

1) If you store a reference to a userdata in the final packed userdata
form (the stored vararg), what happens when the original userdata gets
collected?  A GC association would have to be made from the packed
vararg object (userdata) to the userdata it stores.  Collectable
objects would need to stay "alive" if packed somewhere.

2) If this were used for vectors it would only be a middle-compromise.
 It would use less memory than a table but it wouldn't help for
processing vectors.  If you packed 3 Lua numbers together in a
userdata it wouldn't be in within the word-size of the machine its
running on (not optimal), and it wouldn't be packed together tightly
enough for something like SIMD.