lua-users home
lua-l archive

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


--- begin of test.lua
function test(...)
for i=1, #arg do
print(arg[i])
end
end

test(1,2,3)
--- end of test.lua
[...]
luajitexe: stdin:4: attempt to get length of global 'arg' (a nil value)
[...]
We can see that here luajit generated code tries to read the global
variable "arg" which does not exist.

function test(...)
  for i=1, select("#",...) do
    print((select(i,...)))
  end
end

test(1,2,3)

(or use "{...}" to convert the varargs into a table)

-jcw