local tobool_True = {"1","true","t","yes","y"}
function tobool(str)
if type(str) ~= "string" then str = tostring(str) end
str = string.lower(str)
for i=1,#tobool_True do
if str == string.lower(tobool_True[i]) then
return true
end
end
return false
end
Last edited by Schwender.exe on Thu Oct 19, 2017 9:53 pm, edited 7 times in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
function tobool(val)
if type(val) == "string" then
return val == "true" or val == "t" or val == "1" -- return true for these values, false for all other strings
end
return val -- not a string, use default behavior
end
grump wrote: ↑Wed Oct 18, 2017 12:13 amThat returns true for all strings. Not what OP wants.
The solution to that is to change what the OP wants since OP is wrong. If you're going to redefine what boolean means in the language you're using, you'll end up spending a lot more effort on nothing.
Azhukar wrote: ↑Wed Oct 18, 2017 12:25 amThe solution to that is to change what the OP wants since OP is wrong. If you're going to redefine what boolean means in the language you're using, you'll end up spending a lot more effort on nothing.
You need to enhance your calm. OP just wants to parse a string and convert some values to boolean. There is nothing inherently wrong with that. Maybe he wants to write a config file parser, who knows.