diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-12 01:55:50 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-12 03:33:56 +0200 |
commit | cc57bd2663fb742770a56f205488dbb2c757fb8f (patch) | |
tree | b4951a38f8c1635605c55246348893eb57efe744 /py/obj.c | |
parent | 729e9cce7bd31d3f107a4d6e9498b0fa27119e22 (diff) | |
download | micropython-cc57bd2663fb742770a56f205488dbb2c757fb8f.tar.gz micropython-cc57bd2663fb742770a56f205488dbb2c757fb8f.zip |
mp_obj_equal(): For non-trivial types, call out to type's special method.
Diffstat (limited to 'py/obj.c')
-rw-r--r-- | py/obj.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -117,6 +117,13 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { } else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) { return mp_obj_str_get(o1) == mp_obj_str_get(o2); } else { + mp_obj_base_t *o = o1; + if (o->type->binary_op != NULL) { + mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o1, o2); + if (r != MP_OBJ_NULL) { + return r == mp_const_true ? true : false; + } + } // TODO: Debugging helper printf("Equality for '%s' and '%s' types not yet implemented\n", mp_obj_get_type_str(o1), mp_obj_get_type_str(o2)); assert(0); |