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 <dirk.laurie@gmail.com> wrote:
2011/10/16 Petite Abeille <petite.abeille@gmail.com>:

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

Frivolous?

Now:

   local pack = table.unpack

Before:

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

OK. Frivolous.

Dirk

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.