[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Custom "comparison for equality" in Lua ?
- From: Didier Guillion <didier@...>
- Date: Fri, 3 Jan 2003 10:43:13 +0100
Hi,
In Lua 4.0 I read it is already possible to write a custom "ordered
comparison" function
through the "lt".
Is it a way to write a custom "equal" function ?
Let's take an example :
Let's say I want to implement a "complex number" data type.
It is made of a table, with two indexes "r" and "i"
How can I let the lua interpreter make :
a.r=1
a.i=2
b.r=1
b.i=2
if a==b then print("equality") end
run as expected (i.e. print "equality") ?
Please consider I do not need a trick to implement complex numbers only.
It is just an
example.
The object type I need actually to implement is much more complicated,
with its own
tag and tag methods. I know how to compare such objects for equality, but
I could not
find a way to trap the comparison, except by rewriting the
"LuaO_EqualObj" in the Lua
sources...
Thanks in advance for any advice or comment.
Didier Guillion
Myriad Software
France
mailto:didier@myriad-online.com