Page 1 of 1

bound method type check

Posted: Sun Nov 25, 2018 8:55 pm
by ttmetro
How do I check if an object is either a function or bound method?

Application is specifying an interrupt handler (which can be one of these two things). There is a macro to test for functions, but I could not find anything equivalent for methods.

Re: bound method type check

Posted: Sun Nov 25, 2018 10:16 pm
by loboris

Code: Select all

if ((MP_OBJ_IS_FUN(args[ARG_func].u_obj)) || (MP_OBJ_IS_METH(args[ARG_func].u_obj))) {
}
MP_OBJ_IS_METH define:

Code: Select all

#define MP_OBJ_IS_METH(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_bound_method))
obj.h

Re: bound method type check

Posted: Mon Nov 26, 2018 7:26 pm
by ttmetro
Works perfectly. Thanks!