lua-users home
lua-l archive

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

On Sun, Oct 16, 2011 at 4:27 PM, Dirk Laurie <> wrote:
2011/10/16 Petite Abeille <>:

> To add insult to injury, 5.2 introduces such frivolous function as table.pack -



   local pack = table.unpack


   local function pack(...) local a = {...}; a.n=#a; return a end

OK. Frivolous.


Your definition is equivalent to

  local pack = function (...) return {n=#{...}, ...} end

but the right definition is:

  local pack = function (...) return {n=select("#", ...), ...} end

the "n" field of the top one is somewhat hard to predict when there
are nils among the arguments.