mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
added to_boolean
This commit is contained in:
parent
bc0658b545
commit
b72d36816e
2 changed files with 13 additions and 0 deletions
|
@ -4,3 +4,4 @@ dofile(wea.modpath.."/utils/strings/split.lua")
|
||||||
dofile(wea.modpath.."/utils/strings/polyfill.lua")
|
dofile(wea.modpath.."/utils/strings/polyfill.lua")
|
||||||
dofile(wea.modpath.."/utils/strings/tochars.lua")
|
dofile(wea.modpath.."/utils/strings/tochars.lua")
|
||||||
wea.split_shell = dofile(wea.modpath.."/utils/strings/split_shell.lua")
|
wea.split_shell = dofile(wea.modpath.."/utils/strings/split_shell.lua")
|
||||||
|
wea.to_boolean = dofile(wea.modpath.."/utils/strings/to_boolean.lua")
|
||||||
|
|
12
worldeditadditions/utils/strings/to_boolean.lua
Normal file
12
worldeditadditions/utils/strings/to_boolean.lua
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
--- 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
|
||||||
|
elseif typ == number and arg > 0 then return true
|
||||||
|
elseif arg == "false" or arg == "no" then return false
|
||||||
|
elseif typ ~= "nil" then return true
|
||||||
|
else return false end
|
||||||
|
end
|
||||||
|
return to_boolean
|
Loading…
Reference in a new issue