Skip to content

Commit

Permalink
Correctly work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2605 committed Dec 11, 2024
1 parent f215c5d commit 54c1933
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/optionals/importlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ Value includeNative(DictuVM *vm, int argCount, Value *args) {
pop(vm);

push(vm, OBJ_VAL(module));
module->path = getDirectory(vm, path);
module->path = dirname(vm, path, strlen(path));

char *source = readFile(vm, path);

if (source == NULL) {
runtimeError(vm, "Could not open file \"%s\".", AS_CSTRING(args[0]));
return EMPTY_VAL;
}

ObjFunction *function = compile(vm, module, source);
push(vm, OBJ_VAL(function));
FREE_ARRAY(vm, char, source, strlen(source) + 1);
Expand Down
2 changes: 1 addition & 1 deletion tests/importlib/data/level1.du
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Importlib;

const list = [5, 6, 7];

const Level2 = Importlib.include('./level2.du');
const Level2 = Importlib.include('level2.du');
2 changes: 1 addition & 1 deletion tests/importlib/data/level2.du
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Importlib;

const list = [3, 4, 5];

const Level3 = Importlib.include('./level3.du');
const Level3 = Importlib.include('level3.du');
2 changes: 1 addition & 1 deletion tests/importlib/include.du
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Importlib;

class TestImportLibInclude < UnitTest {
testImportLibInclude() {
const Level1 = Importlib.include('./data/level1.du');
const Level1 = Importlib.include('data/level1.du');

this.assertType(Level1, 'module');
this.assertEquals(Level1.list, [5, 6, 7]);
Expand Down

0 comments on commit 54c1933

Please sign in to comment.