bound method type check

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
ttmetro
Posts: 65
Joined: Mon Jul 31, 2017 12:44 am

bound method type check

Post by ttmetro » Sun Nov 25, 2018 8:55 pm

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.
Bernhard Boser

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: bound method type check

Post by loboris » Sun Nov 25, 2018 10:16 pm

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

ttmetro
Posts: 65
Joined: Mon Jul 31, 2017 12:44 am

Re: bound method type check

Post by ttmetro » Mon Nov 26, 2018 7:26 pm

Works perfectly. Thanks!
Bernhard Boser

Post Reply