lua-users home
lua-l archive

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


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

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

Which is very expensive, but then again if you need the length you likely need to index them using a table anyway.

I've always liked the apairs() suggestion:

for i,a in apairs(...) do
 print(a)
end

Bit cheaper then a table, easy to implement, easy to understand and, like a table, grows linearly with each added element. And, unlike a table, it can handle nils just fine.

I'd like to see it become part of baselib in 5.2.

- Alex