lua-users home
lua-l archive

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


A change from 5.1 to 5.2 was:

>  order metamethods work for different types

There's no PiL for 5.2 yet, so one has to work out
the consequences for oneself:

    When coding __lt(x,y) or __le(x,y), you may assume that
    x or y or both is the object whose metamethod is being
    called, but you do not know which.

E.g. one has to do this:

function myobj.__lt(x,y)
   if getmetatable(x)==myobj
      then return x.cmp(x,y)<0
      else return y.cmp(y,x)>0
   end
end

I hate saying this, but there is something to be said for
a Python-like __cmp that would always belong to the
first argument.