toboolean function

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: toboolean function

Post by zorg »

I sense that this may have been one of those terminological issues, i.e. "what 'toboolean' means to /me/ isn't what it means to /you/"; also, the initial explanation was probably missing a lot. Such is life, but at least now we know what was meant; an "arbitrary string to boolean mapping function".
I'd still highlight that this is atypical lua behaviour though, so strictly speaking it's not how booleans work in lua; but other than that, it may be a valid thing for someone to want to do. (As Azhukar already said)
Me and my stuff :3True 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.
User avatar
Schwender.exe
Prole
Posts: 25
Joined: Mon Oct 16, 2017 6:07 pm
Location: the moon
Contact:

Re: a small toboolean function

Post by Schwender.exe »

brogrammer wrote: Fri Oct 20, 2017 1:47 am
Schwender.exe wrote: Fri Oct 20, 2017 1:29 am yea, sorry for the bad and broken code, atleast it works now and actually does what it's supposed to
no its slow and unnecessarily complicated and does redefine what true means
you know that anything ~= nil and false is supposed to be true right
its still bad code
why not just take the function grump has posted and just add the words you want to be recognized as true
I re-wrote it again, not sure if you saw the new version of it

Code: Select all

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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: toboolean function

Post by grump »

Code: Select all

print(0x1337c0de and true, tobool(0x1337c0de) and true)
> true    false
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 53 guests