特别注意:与很多语言不同,在lua中,“if 0”被认为是true。
if 0 then
print("In lua, 'if 0' is true")
else
print("'if 0''s else part not run")
end
if not 0 then
print("not run")
else
print("In lua, 'if not 0' is false")
end
print("not 0: ", not 0)
print("not 1: ", not 1)
print("not false: ", not false)
print("not nil: ", not nil)
-- output:
-- In lua, 'if 0' is true
-- In lua, 'if not 0' is false
-- not 0: false
-- not 1: false
-- not false: true
-- not nil: true