[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: "attempt to compare number with userdata"
- From: "Jan de Vos" <Jan.de.Vos@...>
- Date: Mon, 24 Nov 2008 16:19:03 +0100
> Peter Cawley wrote:
> >From the manual: " The function |getcomphandler| defines how Lua
> > chooses a metamethod for comparison operators. A metamethod only is
> > selected when both objects being compared have the same type and the
> > same metamethod for the selected operation." Hence userdata cannot
be
> > compared to non-userdata without modifing the Lua source.
> Thank you. Well, I've seen it. I'm actually asking about the reasons
for
> that and also where (approximately) should I modify the Lua sources if
there
> is no reasons.
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.
If you really want to change it, look at lvm.c, specifically, the
luaV_execute function (the cases for OP_LT etc), and further on the
luaV_lessthan function and its friends.
Jan