lua-users home
lua-l archive

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

Consider the following simple example:

Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio
> function T() return true end
> function F() return false end
> mt = {__eq = F, __le = F, __lt = T}
> t = setmetatable({}, mt)
> print(t == t, t < t, t <= t)
true    true    false

t == t gives true even though the __eq would return false, because it always returns true if the operands are the same object.
t <= t and t < t however, honor the result of __le and __lt.

This seems inconsistent to me.
t <= t should always give true, by the same reasoning as t == t always is true
Inversely t < t should always give false.

So, I'd either prefer the same shortcut to be added for __lt and __le, or the shortcut be removed from __eq.
At the very least, it would be nice with some sort of explanation on why the shortcut for __eq was added in the first place.