获取值

基本类型 / 布尔类型

local name = "Alex"
-- Comparison gives a boolean
local name_exists = name ~= ""
-- name_exists = true

local num = 7
local is_ten = num == 10
-- is_ten = false

-- not not turns any value into a boolean
local from_number = not not 42
-- from_number = true

-- Trap: an empty table is true as well
local from_table = not not {}
-- from_table = true

-- Only nil and false give false
local from_nil = not not nil
-- from_nil = false

print("name_exists = " .. tostring(name_exists))
print("is_ten = " .. tostring(is_ten))
print("from_number = " .. tostring(from_number))
print("from_table = " .. tostring(from_table))
print("from_nil = " .. tostring(from_nil))