py: Allow retrieving a function's __name__.

Disabled by default.  Enabled on unix and stmhal ports.
This commit is contained in:
stijn
2015-02-14 18:44:31 +01:00
committed by Damien George
parent 07b8dc68d6
commit 3cc17c69ff
9 changed files with 54 additions and 8 deletions

View File

@@ -70,6 +70,15 @@ STATIC mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_
}
}
#if MICROPY_PY_FUNCTION_ATTRS
STATIC void bound_meth_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if(attr == MP_QSTR___name__) {
mp_obj_bound_meth_t *o = self_in;
dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(o->meth));
}
}
#endif
const mp_obj_type_t bound_meth_type = {
{ &mp_type_type },
.name = MP_QSTR_bound_method,
@@ -77,6 +86,9 @@ const mp_obj_type_t bound_meth_type = {
.print = bound_meth_print,
#endif
.call = bound_meth_call,
#if MICROPY_PY_FUNCTION_ATTRS
.load_attr = bound_meth_load_attr,
#endif
};
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self) {