lua - 如何在 Lua (Corona SDK) 中解析函数参数到变量?

标签 lua coronasdk

例如,我有一个函数:

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/

相关文章:

lua - 添加延迟/定时器

android - 2d 手机游戏

iphone - corona sdk不支持mp3播放?

nginx - 带有 nginx 的 lua 脚本中的持久性 redis 句柄

testing - 具有图形输出的 Lua 测试器?

linux - 如何在同一个linux系统上拥有不同的lua版本

java - 使用 LuaJava 在 Java 项目中调试 Lua

Lua - 可以从表值调用函数及其返回值

graphics - Corona 中所有设备的背景图像大小

lua - Corona sdk线性色带?