[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "attempt to compare number with userdata"
- From: "Alex Davies" <alex.mania@...>
- Date: Tue, 25 Nov 2008 03:36:50 +0900
Nikolai Kondrashov wrote:
Jan de Vos wrote:
I think the only reason is that it protects you from easy-to-make
mistakes. For instance, which metamethod do you want to use when the
left hand side of the inequality is the number? Should the '<'
class-metamethod for 'number' handle all the different kinds of userdata
types you want to compare to? The requirement that both sides be of the
same type makes such problems go away.
Thank you. It could be that I'm not very sharp today (or maybe ever), but
why comparison handling is different from arithmetic handling? I.e. why
should we use "getcomphandler" and not "getbinhandler"?
Atm all comparisons can be handled by EQ, LT, and LE. The VM only uses
these (notted and operands switched where appropriate), and there are only
metamethods for these.
To allow comparisons between different types, at least (I'm tired too) GE,
GT would have to be added - and opcodes added to support these. At least to
allow the selection to be made in an intuitive manner (ie, left value gets
its metamethod called first if present, then second).
That's the only reason I can think of... but it is quite a biggy imo. Well,
besides from the extra error checking (where you find a type has leaked out
that wasn't supposed to get to a numeric compare, for example).