例如,我有一个函数:
myFunction = function(a1,a2,a3)
end;
我想通过代码保存给定 myFunction 的所有参数,在更改 myFunction 参数的数量及其名称后,该代码将是正确的。在我看来可以通过for循环来完成,但我不知道如何在其中调用arguments和#arguments。
最佳答案
local saved_arguments
myFunction = function(...)
-- save the arguments
saved_arguments = {...}
local a1, a2, a3 = ...
-- main code of function
end;
-- Use saved arguments
local last_a1, last_a2, last_a3 = unpack(saved_arguments)
-- do something with last_a1, last_a2, last_a3
-- or use it directly: saved_arguments[1], saved_arguments[2], saved_arguments[3]
关于lua - 如何在 Lua (Corona SDK) 中解析函数参数到变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15359272/