lua-users home
lua-l archive

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


Hi,

On Aug 03, 2007, at 12:48, Ketmar Dark wrote:

Lua 5.1, right?

Right.

 table.insert doesn't work right on sparse tables,
'cause it not use xxx.n anymore.

Yes, nothing seems to work as expected when nil values are involved :(

 you should emulate with your code or
don't use nils in arrays.

Well... in this specific case... I would like to manipulate a varargs (aka '...') by adding an additional argument to it... varargs can legitimately contain nil values... e.g.:

local function AddOne( anExta, ... )
    local aList = { n = select( '#', ... ) + 1, anExta, ... }

    return unpack( aList, 1, aList.n )
end

local function Test( ... )
    return AddOne( 'extra', ... )
end

print( Test( nil, 'a', nil ) )

> extra   nil     a       nil

How does one generalize that to insert a value anywhere in a varargs?