lua-users home
lua-l archive

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

2018-06-06 9:15 GMT+02:00 Viacheslav Usov <>:

> 1. Lua describes 'and' and 'or' is binary operator

This puts the finger on the sore spot. The manual is misleading.

Since they use short-circuit evaluation, they are not operators. They
are evaluation directives: control structures that return a value. For
boolean arguments, they happen to behave like operators would. We
really should have had '&&' and '||' for logical consitency.

Of course, from Lua 5.3 on you can try to make '&' and '|' do the job:

debug.setmetatable(true,{__band = function(a,b) return a and b end;
__bor = function(a,b) return a or b end; __bnot = function(a) return
not a end})

but the precedence then is highly confusing.