Minetest-WorldEditAdditions/worldeditadditions/utils/strings/to_boolean.lua

13 lines
385 B
Lua
Raw Normal View History

2021-10-10 23:39:30 +02:00
--- Converts input to a value of type Boolean.
-- @param arg any Input to convert
-- @returns boolean
local function to_boolean(arg)
local typ = type(arg)
if typ == "boolean" then return arg
2021-11-07 16:36:43 +01:00
elseif typ == "number" and arg > 0 then return true
2021-10-10 23:39:30 +02:00
elseif arg == "false" or arg == "no" then return false
elseif typ ~= "nil" then return true
else return false end
end
return to_boolean