diff options
author | stijn <stinos@zoho.com> | 2015-02-14 18:44:31 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-03-20 23:13:32 +0000 |
commit | 3cc17c69ffd64dca55fe613f6e931585d8893c0d (patch) | |
tree | 73fe88917c5b65ac3fdb679e5aee7338ed2fa66b /py/objboundmeth.c | |
parent | 07b8dc68d667c212f9a3710b74e90e05e1032316 (diff) |
py: Allow retrieving a function's __name__.
Disabled by default. Enabled on unix and stmhal ports.
Diffstat (limited to 'py/objboundmeth.c')
-rw-r--r-- | py/objboundmeth.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 7698ed29f..69ae263af 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -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) { |