小编sii*_*kee的帖子

解压缩功能问题在Lua

我有以下unpack()功能:

function unpack(t, i)  
    i = i or 1  
    if t[i] then  
        return t[i], unpack(t, i + 1)  
    end  
end  
Run Code Online (Sandbox Code Playgroud)

我现在在以下测试代码中使用它:

t = {"one", "two", "three"}  
print (unpack(t))  
print (type(unpack(t)))  
print (string.find(unpack(t), "one"))  
print (string.find(unpack(t), "two"))
Run Code Online (Sandbox Code Playgroud)

哪个输出:

one two three  
string  
1   3  
nil  
Run Code Online (Sandbox Code Playgroud)

令我困惑的是最后一行,为什么会有结果nil呢?

lua lua-table

3
推荐指数
1
解决办法
1565
查看次数

标签 统计

lua ×1

lua-table ×1