lua-users home
lua-l archive

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


On Fri, Jul 1, 2016 at 6:09 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
> There are few smaller steps we can make:>
> *  Solve the `pack()`/`unpack()` symmetry problem.

This feels like a good one - otherwise I'm in the "Houston, I don't
really think we have a problem" camp.

function foo(...)
   local args = table.pack(...)
   for i = 1,#args do
     ..
   end
end

Easy to use and explain!

This table clearly has a metatable to override __len (the 'n' key
becomes an implementation detail and could be scheduled for
deprecation).

Hence, make __index point to table. This code should behave exactly as
Hisham expects:

local t = table.pack(10,nil,'hello')
foo(t:unpack())

> *  Enhance the table library to allow non-sequence based array
> implementations by adding a library metamethod `__resize` or `__setsize`, so
> that `table.insert()` and `table.remove()` can adjust the array sizes
> accordingly (`table.move()` is more complicated).

This makes sense, so that our 'varargs' object can have
t:insert(2,nil) and #t gets bumped up.

steve d.