lua-users home
lua-l archive

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


2014-11-23 17:51 GMT+02:00  <philippe.castagliola@free.fr>:

> Concerning the "eq" metamethod, in the Lua5.3 Reference Manual
> it is written "The result of the call is always converted to a boolean"
> and ... I wonder why?

The reason sits deep in the design of the Lua virtual machine.

Basically, the VM does not work with Lua booleans at all. For example,
the bytecode for `b = y==z` can be written in pseudocode as

   if y==z then b=toboolean(1) else b=toboolean(0) end

> I have the feeling this is an unnecessary constraint. Why not just leave
> the final decision to the programmer?

The programmer can make the decision whether to use the `==`
operator or to call the metamethod explicitly as a function.