[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 - small enhancement for table.unpack
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Wed, 29 Jun 2011 17:29:04 +0200
On 29/06/2011 10.46, Daurnimator wrote:
On 29 June 2011 17:25, Lorenzo Donati<lorenzodonatibz@interfree.it> wrote:
Hi all!
[...]
I'd much rather a change where table.pack just returns a table and length:
function table.pack(...)
return {...},select("#",...)
end
==> this way we dont get the arbitary 'n' key; and unpack is (mostly)
symmetrical:
Mmm, but what's the use of pack, then?
local t,t_n = table.pack(...)
you can write also in 5.1.4:
local t,t_n = {...}, select('#',...)
and it isn't much more verbose.
table.pack is useful as it is because it is very short in the common
case of storing away all the vararg info in one shot (with n, so it
handles possible nils).
Perhaps, table.pack could still return n as a second argument, but the
injection of n in the table is very useful IMO.
print(unpack(t,1,t_n))
Daurn.
cheers
-- Lorenzo