diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-19 14:52:07 -0800 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-19 14:52:07 -0800 |
commit | 2c7a1b2ad193e25749dd5821a8af95173ae290cb (patch) | |
tree | 201a5cca563eaad2e76651add86b8dc4de923c1a /py/builtinimport.c | |
parent | f438b936e0edcbc3eab9af6cc3513db1f01ab17e (diff) | |
parent | d720ab5236015124a13c09175ed674e565414faa (diff) | |
download | micropython-2c7a1b2ad193e25749dd5821a8af95173ae290cb.tar.gz micropython-2c7a1b2ad193e25749dd5821a8af95173ae290cb.zip |
Merge pull request #197 from pfalcon/mod-singletons
Implement modules as singletons Python semantics.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index e3c630a0a4..92d5d5ac9f 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -28,8 +28,13 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { } */ - // find the file to import qstr mod_name = mp_obj_get_qstr(args[0]); + mp_obj_t loaded = mp_obj_module_get(mod_name); + if (loaded != MP_OBJ_NULL) { + return loaded; + } + + // find the file to import mp_lexer_t *lex = mp_import_open_file(mod_name); if (lex == NULL) { // TODO handle lexer error correctly |