lua-users home
lua-l archive

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


On Thu, Jan 7, 2016 at 12:29 PM,  <joec@infoark.com> wrote:
> 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?

No, that's exactly what it's saying. However, zero is NOT false in
Lua, unlike in C.

Your bitwise operation is returning a numeric zero, which is neither
the specific value false, nor the specific value nil. Therefore, the
conditional is considered true, therefore the first block is executed.

Basically, you should always use a conditional operator (!= 0 perhaps)
when using the result of bitwise ops in a conditional.

/s/ Adam