diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-03 22:55:16 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-03 22:55:16 +0000 |
commit | 97334c85d0b53ef1648eb76ec6e9e2b1efab1f97 (patch) | |
tree | d10f6b6b7ca3394e6f7dc31ca55e0df2b39abe02 /py/lexerunix.c | |
parent | 25f417c08c2cdb5c4a7564d1e69766c0448d7984 (diff) | |
parent | b7aa72710ee6798c6d2bc2632be24206e526fc1e (diff) | |
download | micropython-97334c85d0b53ef1648eb76ec6e9e2b1efab1f97.tar.gz micropython-97334c85d0b53ef1648eb76ec6e9e2b1efab1f97.zip |
Merge remote-tracking branch 'upstream/master'
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? +} |