diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-03 14:03:48 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-03 14:03:48 +0000 |
commit | 66028ab6dcd1b2ec9504c3473d817649935a4a1e (patch) | |
tree | c441ee4d665b3218e235dec24dd5a66a6fe050ef /py/lexerunix.c | |
parent | aae7847508e2a9555ad3276c5cd4f42b2e66686c (diff) | |
download | micropython-66028ab6dcd1b2ec9504c3473d817649935a4a1e.tar.gz micropython-66028ab6dcd1b2ec9504c3473d817649935a4a1e.zip |
Basic implementation of import.
import works for simple cases. Still work to do on finding the right
script, and setting globals/locals correctly when running an imported
function.
Diffstat (limited to 'py/lexerunix.c')
-rw-r--r-- | py/lexerunix.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/py/lexerunix.c b/py/lexerunix.c index 398cb792a7..14c28c16d9 100644 --- a/py/lexerunix.c +++ b/py/lexerunix.c @@ -58,3 +58,23 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { return mp_lexer_new_from_str_len(filename, data, size, true); } + +/******************************************************************************/ +/* unix implementation of import */ + +// TODO properly! + +static const char *import_base_dir = NULL; + +void mp_import_set_directory(const char *dir) { + import_base_dir = dir; +} + +mp_lexer_t *mp_import_open_file(qstr mod_name) { + vstr_t *vstr = vstr_new(); + if (import_base_dir != NULL) { + vstr_printf(vstr, "%s/", import_base_dir); + } + vstr_printf(vstr, "%s.py", qstr_str(mod_name)); + return mp_lexer_new_from_file(vstr_str(vstr)); // TODO does lexer need to copy the string? can we free it here? +} |