首页 技术 正文
技术 2022年11月8日
0 收藏 678 点赞 1,997 浏览 1086 个字

问题:对可变参数传递的时候,采用如下方案:

local cellData

=

{
MsgText = msgText,
Param = …,
CallBackFunc = callBackFunc,
CallBackContext = callBackContext,
Index = newIndex,
}

这里面其实Param只传递看一个参数, 大致总结一下可变参数的使用:

(1)…,标记为变长参数,lua在解析的时候会将相关参数保存在局部变量中

(2)select()函数可以遍历其中的参数

function printargs(…)
local num_args = select(“#”, …)
for i = , num_args do
local arg = select(i, …)
print(i, arg)
end
end

(3)使用

local t = { … }将参数转换为table

<!–
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
–>

(4)函数中

-- 

可以
print(“1”, …)
— 被调整为一个参数
print(…, “1”

)

如果想把可变参数放在前面,需要特殊处理,一种方式就是讲后面的参数和前面的参数一起重新打包

function append(...)
local t = { ... }
table.insert(t, x)
-- 将key为数字的转换为数组
return unpack(t)
end
 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,953
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,478
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,290
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,107
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,739
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,773