[09 Mar 2008] a comparison test that fails

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Dwayne

[09 Mar 2008] a comparison test that fails

Post by Dwayne »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 9 Mar 2008 11:30:16 +1100

Hi again,

Please verify whether this is by design or is another bug. I have written a function to workaround it for the meantime.

Code: Select all

c="account"
grandchild={__type="object"}
child={__type="object"}
inherited={__type="object", account={__type="object"}}

debugprint (inherited[c]=grandchild) ; __type="object" = __type="object" --> 0 (false)
debugprint (child=grandchild)        ; __type="object" = __type="object" --> 0 (false)
debugprint (grandchild=grandchild)   ; __type="object" = __type="object" --> 1 (true)
Regards,

Dwayne
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[21 Mar 2008] Re: a comparison test that fails

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 21 Mar 2008 17:06:02 +0100

This is correct behaviour. The relational operators compare tables, userdata, and functions by reference. Values are only equal if they are the very same object, e.g.

Code: Select all

a = {x = 1, y = 0}
b = {x = 1, y = 0}
c = a

DebugPrint(a=b)  --> FALSE
DebugPrint(a=c)  --> TRUE
If you want the operators to behave in a different way, you can install relational metamethods.
Locked