-- 没有解析函数:把文本转成小写再比较
local str_value = "True"
local bool_value1 = str_value:lower() == "true"
-- bool_value1 = true
-- 多个词都算 true:用一个词集合
local true_words = {["true"] = true, yes = true,
["1"] = true}
local str_answer = "yes"
local answer = str_answer:lower()
local bool_value2 = true_words[answer] == true
-- bool_value2 = true
-- 陷阱:文本 "false" 在条件中为 true
local str_false = "false"
local bool_value3 = false
if str_false then
bool_value3 = true
end
-- bool_value3 = true
print("bool_value1 = " .. tostring(bool_value1))
print("bool_value2 = " .. tostring(bool_value2))
print("bool_value3 = " .. tostring(bool_value3))