[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: why is comparison not handled like other binary operatorsw/metamethods?
- From: Rici Lake <lua@...>
- Date: Mon, 2 Oct 2006 14:47:48 -0500
On 2-Oct-06, at 2:37 PM, Jerome Vuarand wrote:
Workarounds:
- you can simply call yourself the comparison function instead of
using the operator:
if foometatable.eq(foovar, 32) then foofunc() end
- you can cast one of your values to the same type as the other before
the comparison operator is evaluated
if foovar==footype.new(32) then foofunc() end
Another possibility that suggests itself is:
if foovar - 32 == 0 then ...
but that would only work if __sub were clever enough to return a
(lua_Number) 0 instead of a (foo) 0. That might generally be a good
idea, for numbers representable as lua_Numbers.