Ho questa funzione di test che consente di stampare semplicemente i valori passati ad essoLua unpack() argomenti che pasticciano
function test1(...)
for k, v in ipairs(arg) do
print(v)
end
end
function test2(...)
for k, v in pairs(arg) do
print(v)
end
end
-- GOOD behavior
test1(1, 2, 3, 4) -- produces 1 2 3 4
test2(1, 2, 3, 4) -- produces 1 2 3 4
-- BAD behavior
test1(unpack({1,2}), 3, 4) -- produces 1 3 4
test2(unpack({1,2}), 3, 4) -- produces 1 3 4 3
Qualcuno può spiegare questo comportamento a me?
Grazie. Era quello che stavo cercando :) –
Per i curiosi: [dove tutti possono avere una lista di espressioni in Lua?] (Http://stackoverflow.com/a/31782250/183120) – legends2k