summaryrefslogtreecommitdiff
path: root/unix/main.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-03 14:03:48 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-03 14:03:48 +0000
commit66028ab6dcd1b2ec9504c3473d817649935a4a1e (patch)
treec441ee4d665b3218e235dec24dd5a66a6fe050ef /unix/main.c
parentaae7847508e2a9555ad3276c5cd4f42b2e66686c (diff)
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 'unix/main.c')
-rw-r--r--unix/main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/unix/main.c b/unix/main.c
index 376dbc0c0..c23a8e54c 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -105,6 +105,18 @@ static void do_repl(void) {
}
void do_file(const char *file) {
+ // hack: set dir for import based on where this file is
+ {
+ const char * s = strrchr(file, '/');
+ if (s != NULL) {
+ int len = s - file;
+ char *dir = m_new(char, len + 1);
+ memcpy(dir, file, len);
+ dir[len] = '\0';
+ mp_import_set_directory(dir);
+ }
+ }
+
mp_lexer_t *lex = mp_lexer_new_from_file(file);
//const char *pysrc = "def f():\n x=x+1\n print(42)\n";
//mp_lexer_t *lex = mp_lexer_from_str_len("<>", pysrc, strlen(pysrc), false);