lua-users home
lua-l archive

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



On Sep 18, 2016, at 5:57 AM, Soni L. <fakedme@gmail.com> wrote:

A boolean is a logical type with a value of true or false. It may internally be represented as a single bit, but that is an implementation detail. Bitwise inversion (a more accurate name for bitwise NOT) does not apply to booleans, any more than it applies to hats.

C and its various offspring frequently allow an integer value to be INTERPRETED in a boolean manner (using the zero vs non-zero convention). For this reason, in this class of language, it is valid to use boolean operators on integers (though with caution), since the integer type is overloaded. This is not the case for Lua, so your assertion is incorrect.

—Tim

Is there any good reason to not do it the Rust way? Lua has a separate boolean type, just like Rust. You can't add/subtract/multiply/divide a Rust boolean with a Rust integer and you can't add/subtract/multiply/divide a Lua boolean with a Lua integer. But what Rust does let you do is use bitwise not on a boolean, and it saves an operator.


Is there any good reason TO do it the Rust way? What Rust does is overload an operator, is that better? If so, why?

—Tim