diff options
author | Damien George <damien.p.george@gmail.com> | 2015-09-15 14:56:13 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-10-12 13:46:01 +0100 |
commit | 3c9c3687d6c1001b88ef6dde200566456a1f2641 (patch) | |
tree | 23674a035d588eb89c8f8d2d0fb50ed58194bd8a /py/objmodule.c | |
parent | 408b74d74ce8de806f8718a02d350b8326d89361 (diff) |
py: Add support to call __init__ from a builtin module on first import.
Diffstat (limited to 'py/objmodule.c')
-rw-r--r-- | py/objmodule.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objmodule.c b/py/objmodule.c index 940a8daf2..63cccde2b 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -215,6 +215,17 @@ mp_obj_t mp_module_get(qstr module_name) { if (el == NULL) { return MP_OBJ_NULL; } + + if (MICROPY_MODULE_BUILTIN_INIT) { + // look for __init__ and call it if it exists + mp_obj_t dest[2]; + mp_load_method_maybe(el->value, MP_QSTR___init__, dest); + if (dest[0] != MP_OBJ_NULL) { + mp_call_method_n_kw(0, 0, dest); + // register module so __init__ is not called again + mp_module_register(module_name, el->value); + } + } } // module found, return it |