lua-users home
lua-l archive

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

On 29/06/2011 10.46, Daurnimator wrote:
On 29 June 2011 17:25, Lorenzo Donati<>  wrote:
Hi all!


I'd much rather a change where table.pack just returns a table and length:

function table.pack(...)
     return {...},select("#",...)

==>  this way we dont get the arbitary 'n' key; and unpack is (mostly)

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.



-- Lorenzo