[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Construct table from multiple values with named keys
- From: Petite Abeille <petite.abeille@...>
- Date: Wed, 9 May 2012 19:56:44 +0200
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, ... )
end
return aMap
end