你猜 notice 是true 还是false
local notice = false
notice = notice or true
print(notice)
Lua 中 or 规则:左边为假值,就返回右边;左边为真值,直接返回左边。
Lua 假值只有两个:false、nil,其余全是真值。
local notice = false -- notice = false(假值)
notice = notice or true -- 左边是 false,所以取右边 true
print(notice) -- 输出 true
三元
local notice = false
notice = notice == nil and true or notice
print(notice) -- false
local notice2 = nil
notice2 = notice2 == nil and true or notice2
print(notice2) -- true