调用select时,必须传入一个固定实参selector(选择开关)和一系列变长参数。如果selector为数字n,那么select返回它的第n个可变实参,否则只能为字符串"#",这样select会返回变长参数的总数。例子代码:
复制代码 代码如下:
do
function foo(...)
for i = 1, select('#', ...) do //get the count of the params
local arg = select(i, ...);//select the param
print("arg", arg);
end
end
foo(1, 2, 3, 4);
end
最后
以上就是机智煎饼最近收集整理的关于Lua select函数用法实例的全部内容,更多相关Lua内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复