Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 为什么';如果不是s';和';s~=nil';他们有什么不同?_Lua - Fatal编程技术网

Lua 为什么';如果不是s';和';s~=nil';他们有什么不同?

Lua 为什么';如果不是s';和';s~=nil';他们有什么不同?,lua,Lua,在Lua中,我写了以下内容: for s in string.gmatch(path, "([^'\\']+)") do if not s then -- if s ~= nil then table.insert(path_tb, s) print(s) end end 如果我用替换如果不是s那么如果s~=nil那么我得到一个不同的结果。这背后的原因是什么?不是s当s为nil或s为false时,s就是真的。如果s~=nil,那么几乎等同于如果s

在Lua中,我写了以下内容:

for s in string.gmatch(path, "([^'\\']+)") do
    if not s then -- if s ~= nil then
        table.insert(path_tb, s)
        print(s)
    end
end

如果我用
替换
如果不是s那么
如果s~=nil那么
我得到一个不同的结果。这背后的原因是什么?

不是s
s
为nil或
s
为false时,s就是真的。

如果s~=nil,那么
几乎等同于
如果s,那么路径的值是什么?我看不出这两者在迭代器上使用是多么有用
s
将始终是字符串(空时从不为假,也从不为
nil