I'm having trouble understanding how the expressions ""==true and ""==false both evaluate to false.
Trying the following in the lua interpreter and ilua result in the same output:
> =""==true
false
> =""==false
false
Or executing the following:
print(""==true)
print(""==false)
print(""==nil)
Outputs
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
false
false
false
>
Another example:
> =""~=true
true
> =""==false
false
When the following code is run:
if "" then -- if ""==true
print "was true"
end
if not "" then -- if ""==false
print "was not true"
end
The output is (seemingly inconsistently)
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
was true
>
As expected per the Lua FAQ which states
C-like languages regard 0 as equivalent to false, but this is not true for Lua. Only an explicit false or nil are equivalent to false. When in doubt, make the condition explicit, e.g. if val == nil then ... end unless the value is actually boolean.
How can a value be not equal to true,false or nill?
""is an empty String. So, it is nottrue, notfalseand neithernill. - Minoru>>> ""==True False >>> ""==False False >>> ""==None False:) - catwell