diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-06-06 00:10:40 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-06-06 00:10:58 +0300 |
commit | 07408cbd1f1c10b6d4784dccdea3f14e44605dca (patch) | |
tree | c28a12483f505df9170c99cb286a27f6a8ade291 /py/builtinimport.c | |
parent | d7192fe68c96974691f880b5b82b642bf891cb23 (diff) |
unix: Make micropython -m <module> work for frozen modules.
This requires some special handling, which was previosuly applied only to
the main code path.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 5cab1d59b..aa8a8973c 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -268,6 +268,14 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args) { mp_lexer_t *lex = mp_find_frozen_module(mod_str, mod_len); if (lex != NULL) { module_obj = mp_obj_new_module(module_name_qstr); + // if args[3] (fromtuple) has magic value False, set up + // this module for command-line "-m" option (set module's + // name to __main__ instead of real name). + // TODO: Duplicated below too. + if (fromtuple == mp_const_false) { + mp_obj_module_t *o = module_obj; + mp_obj_dict_store(o->globals, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__)); + } do_load_from_lexer(module_obj, lex, mod_str); return module_obj; } |