I find it hard to understand how the expressions ""==true and ""==false are evaluated as false .
The following is done in the lua and ilua interpreter:
> =""==true false > =""==false false
Or follow these steps:
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 executed:
if "" then -- if ""==true print "was true" end if not "" then -- if ""==false print "was not true" end
Result (seemingly inconsistent)
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio was true >
As expected in the Lua FAQ, which states
C-like languages โโconsider 0 the equivalent of false, but this is not true for Lua. Only explicit false or zero is equivalent to false. when in doubt, make the condition explicit, for example. if val == nil then ... end if the value is actually not logical.
How can a value not be true , false or nill ?
source share