lua-users home
lua-l archive

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



On Jan 31, 2005, at 03:10, Rici Lake wrote:

You can do that by giving both tables the same __eq metamethod, although I'm not a great fan of that solution. See below.

By the way, where are all those 'magic' operators defined?

Note the difference between the __eq approach for equality (in which equality is defined by the compared values) and the above approach (in which equality is defined by the containing table).

Ok. I will dig deeper in those exotic metatable operators :)

In the meantime, here is the monster I have concocted... sigh...

-- instance method to compare the given object with this list for equality
        this.equals = function( anObject )
                if this == anObject then
                        return true
                end

                if anObject ~= nil then
                        local count = this.size()

                        if count == anObject.size() then
                                for index = 1, count do
                                        local aValue = this.get( index )
local anotherValue = anObject.get( index )

if this.isKindOf( aValue ) == true and aValue.equals( anotherValue ) == false then
                                                return false
                                        end

                                        if aValue ~= anotherValue then
                                                return false
                                        end
                                end

                                return true
                        end
                end

                return false
        end


Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/