lua-users home
lua-l archive

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


On Dec 16, 2009, at 9:08 PM, Cosmin Apreutesei wrote:

>> f( 'foo', nil, 'bar', nil )
> 
> That n is exactly what I would've scrapped. 

You cannot just scrap that as it tells unpack how long your list of argument is. Without it, you could never properly unpack arguments with nils.

Consider:

print( #{ 'a', nil, 'b', nil } )

> 1

Therefore:

unpack( { 'a', nil, 'b', nil } ) would pass only the first parameter if not told otherwise.

So:

f( 'a', nil, 'b', nil ) != f( unpack( { 'a', nil, 'b', nil } ) ) = f( 'a' )
f( 'a', nil, 'b', nil ) = f( unpack( { 'a', nil, 'b', nil }, 1, 4 ) )