lua-users home
lua-l archive

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


On Sep 22, 2013, at 4:47 AM, Jayanth Acharya <jayachar88@gmail.com> wrote:

> In the list of published metamethods available in every document that I read, I seem to be unable to find __gt and __ge anywhere. Are those really no present, or am I missing something (like checking the right place, doc) ?
> 
> If those are really absent, then does it mean we cannot use metatables to support the > and >= operators for say table comparison ?

Short answer, Lua rewrites > and >= at compile time so that it uses < and <=. So if you implement __lt and __le then you will cover all the possibilities. In fact __le is optional as well, if you don't have one Lua will use __lt by assuming (a <= b) is the same as not (b < a).

--Tim