lua-users home
lua-l archive

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


Am 25.07.2016 um 17:48 schröbte steve donovan:
On Mon, Jul 25, 2016 at 5:42 PM, Doug Currie <doug.currie@gmail.com> wrote:
condition expression with a comparison operator or a boolean variable.
Otherwise the intention is not clear. Use strong typing, avoid automatic
conversions!

Increasingly I'm tending that way - the amount of magic that can be
crammed into a simple if is worrying.  One thing which would
definitely be a misfeature would be a _bool metamethod.

Why?

Lua already has boolean conversions for all of its values (everything except `nil` and `false` converts to `true`). The question is whether the programmer should be able to decide which boolean is chosen for a particular value.

And btw., `__bool` would allow you to *forbid* automatic conversion to booleans as well, simply by throwing an error in the `__bool` metamethod.


Philipp