为什么'if not s'和's ~= nil'不同?

  • 本文关键字:nil 不同 if not 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

如果我用if s ~= nil then替换if not s then,我会得到不同的结果。这背后的原因是什么?

s为零或s为假时,not s为真。

相关内容

最新更新