lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks for the clarification, didn't see it like that. 

I thought that when the result of the if _expression_ evaluates to true it takes the if branch, but this appears to be the opposite from what you're saying?

-------- Original Message --------
Subject: Re: Bitwise confusion?
From: "Soni L." <fakedme@gmail.com>
Date: Thu, January 07, 2016 2:44 pm
To: Lua mailing list <lua-l@lists.lua.org>

On 07/01/16 05:35 PM, joec@infoark.com wrote:
> I'm running LUA v5.3.2. In the code below shouldn't the following if
> statements produce the same results?
>
> -----code below here------
>
> local tracemask = 0x00000040
> local traceflgs = 0
>
> val = traceflgs & tracemask
>
> if (traceflgs & tracemask) then
> print("val=" .. val .. "\n")
> else
> print("Branch not taken...\n")
> end
>
> if ((traceflgs & tracemask) > 0) then
> print("val=" .. val .. "\n")
> else
> print("Branch not taken...\n")
> end
>
if 0 then
print"0 is true"
else
print "0 is false"
end

if 0 > 0 then
print "0 > 0 is true"
else
print "0 > 0 is false"
end

http://www.lua.org/manual/5.3/manual.html#2.1

"Both nil and false make a condition false; any other value makes it true."

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.