Page 1 of 1

[09 Mar 2008] a comparison test that fails

Posted: Sat Jun 13, 2020 5:31 pm
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

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

Posted: Sat Jun 13, 2020 5:31 pm
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.