lua-users home
lua-l archive

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


Am 11.05.2010 19:22, schrieb Patrick Donnelly:
function f(x,...) print(#...) end
f(1,2,3,4)
stdin:1: attempt to get length of a number value
It doesn't work, because "#..." expands to "#2,3,4" which doesn't make sense.

local function f(...)
    print(#{...})
end
f("A","B","C")

works fine and prints 3 (at the cost of creating a temporary table)

    1    [4]    GETGLOBAL    1 -1    ; print
    2    [4]    NEWTABLE     2 0 0
    3    [4]    VARARG       3 0
    4    [4]    SETLIST      2 0 1    ; 1
    5    [4]    LEN          2 2
    6    [4]    CALL         1 2 1
    7    [5]    RETURN       0 1