问题
When using the Lua 5.2 API, the code below prints "nil"
function __debug(szName, ...)
print(type(arg));
end
__debug("s", 1, 2, 3, 4);
But this code does work when using Lua 5.1, and prints "table"
回答1:
If you are referring to vararg function, the arg table was deprecated already in Lua 5.1. In Lua 5.2, you can use table.pack to create arg if you need it:
function debug(name, ...)
local arg = table.pack(...)
print(name)
for i=1,arg.n do
print(i, arg[i])
end
end
回答2:
That's because arg has been deprecated since Lua 5.1. It only remained as a compatibility feature.
References: Lua 5.1 manual, unofficial LuaFaq
a workaround is using this line to generate a table called arg:
local arg={...}
来源:https://stackoverflow.com/questions/9786051/getting-arg-to-work-in-a-varag-function-in-lua-5-2-integrated-in-delphi