跳到主內容

【Lua】【型別】 nil - 布林

nil

nil是Lua裡的一個特殊值,代表什麼也沒有。其型別也是nil

type(nil) -- => nil

布林

布林值只有truefalse

只要不是nil或是false都為真, 包含0、空表、空字串 。

if 0 then
  print("0 is true")
end

if {} then
  print("{} is true")
end

if "" then
  print [["" is true]]
end

~= 不等於

weeks = {"週一","週二","週三","週四","週五","週六","週日", "Opps"}

if #weeks ~= 7 then
  error("Weeks length must is 7.")
end