lua-users home
lua-l archive

Re: Second class nil? Strong and weak nils in tables?

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


On Oct 27, 2007, at 23:50, Duck wrote:
[This topic should be promoted to meta-thread status as it simply refuses to die :P]
That's exactly my point. That code is the clear and natural way to use {...}, but it also breaks whenever any of the args in ... is nil.
For reference purpose, the canonical way to enumerate variable length arguments in 5.1 is with 'select':
for anIndex = 1, select( '#', ... ) do
 local aValue = select( anIndex, ... )
 -- do something with value
end
Converting a list into a table is lossy, precisely because you can't have explicit nils in tables.
Table size needs to be recorded explicitly in that case:
local someArguments = { n = select( '#', ... ), ... }
for anIndex = 1, someArguments.n do
 local aValue = someArguments[ anIndex ]
 -- do something with value
end
unpack( someArguments, 1, someArguments.n )
Which looks suspiciously like the pre-5.1 way of doing things as Rici Lake humorously pointed out:
<Digression>
If this seems like a reversion to Lua 4 and the old 'n'
field, so be it.... you could use a different key if you liked
</Digression>
http://lua-users.org/lists/lua-l/2007-06/msg00452.html

AltStyle によって変換されたページ (->オリジナル) /