lua-users home
lua-l archive

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

On May 9, 2012, at 7:18 PM, Emeka wrote:

>               local t=table.pack(...)
>               local n=t.n
>               t.n=nil

Luiz uses table.pack, which adds a 'n' key to hold the overall length of the  arguments. This is necessary to account for nil values.

That said, using table.pack seems to be more trouble than anything in that case. Using select directly seems to be more straightforward.

For example: 

function NamedTable( someNames, ... )
  local aMap = {}

  for anIndex = 1, select( '#', ... ) do
    aMap[ assert( someNames[ anIndex ] ) ] = select( anIndex, ... )

  return aMap