boolean类型只有两个值:true
和false
。
print(type(true)) --> boolean
print(type(false)) --> boolean
print(type(nil)) --> nil
在做条件判断时,Lua把false
和nil
都看成是false
:
-- test.lua
if false or nil then
print('at least one of them is false')
else
print('both of them are false')
end
执行结果如下:
> lua test.lua
both of them are false