lua-users home
lua-l archive

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


> Officially, it's not correct to do "table.unpack{nil, 'something',
> 'another'}" because the nil makes it legitimate for table.unpack() to
> regard the length of the table as 0.
>
> However, all Lua implementations I've checked (Lua 5.1, 5.2, 5.3, JIT)
> do calculate #{nil,a,b} to be 2, not 0. Let's assuming a and b are
> never nil.
>
> So I was wondering if this is a special case we can trust to always work.

Depends on what you call "safe", but remember:

    > t = {nil, 2, 3}
    > #t
    3
    > t={}
    > t[2] = 2
    > t[3] = 3
    > #t
    0

-- 
Pierre Chapuis