解压缩功能问题在Lua
发布时间:2020-12-14 21:42:21 所属栏目:大数据 来源:网络整理
导读:我有以下unpack()函数: function unpack(t,i) i = i or 1 if t[i] then return t[i],unpack(t,i + 1) end end 我现在在以下测试代码中使用它: t = {"one","two","three"} print (unpack(t)) print (type(unpack(t))) print (string.find(unpack(t),"one"))
我有以下unpack()函数:
function unpack(t,i) i = i or 1 if t[i] then return t[i],unpack(t,i + 1) end end 我现在在以下测试代码中使用它: t = {"one","two","three"} print (unpack(t)) print (type(unpack(t))) print (string.find(unpack(t),"one")) print (string.find(unpack(t),"two")) 哪个输出: one two three string 1 3 nil 令我困惑的是最后一行,为什么结果为零? 解决方法
如果函数返回多个值,除非将其用作最后一个参数,否则仅采用第一个值.
在你的例子中,string.find(unpack(t),“one”)和string.find(unpack(t),“two”),“two”和“three”被丢弃,它们相当于: string.find("one","one") --3 和 string.find("one","two") --nil (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |