lua-users home
lua-l archive

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


On 30 June 2011 01:29, Lorenzo Donati <lorenzodonatibz@interfree.it> wrote:
>
> 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
>
>

The purpose of bringing back  table.pack is to make it so that doing 2
vararg related operations doesn't have to happen; apparently they are
quiet expensive: so table.pack is introduced where it figures out the
length and packs a table all at once.