_cmp Metamethod for ==

I run the code below on my Agent. I expect it to print “true” since I implemented _cmp. But it prints false. Should it print true?

class MyClass {
    function _cmp(other) { return 0; }    

local c1 = MyClass();
local c2 = MyClass(); 
server.log(c1 == c2);

That took me by surprise, but I checked in the upstream Squirrel documentation and it turns out that metamethod _cmp is only used for relative comparisons < <= >= >. The equality operator == can’t be overriden and always reports object identity not equivalence, which is a bit of a shame.


Then the following two pages of Electric Imp documentation are wrong. They say “When Squirrel encounters any one of the comparison operators — ==, !=, <=, >=, < and > — to the right of an object, it immediately looks in the object’s specified delegate.” Where should I report it?

It looks like the documentation pages have been corrected, by some strange coincidence.

That’d probably be Tony :slight_smile:

I believe it’s termed ‘anticipating customer need’.