Skip to content

Commit

Permalink
wren/vm: Allow wrenInterpret to call foreign function (complement 344…
Browse files Browse the repository at this point in the history
  • Loading branch information
mhermier committed Jun 28, 2020
1 parent e539279 commit 3676a5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/vm/wren_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,12 +1447,9 @@ WrenInterpretResult wrenInterpret(WrenVM* vm, const char* module,
wrenPushRoot(vm, (Obj*)closure);
ObjFiber* fiber = wrenNewFiber(vm, closure);
wrenPopRoot(vm); // closure.

WrenInterpretResult result = runInterpreter(vm, fiber);

vm->fiber = NULL;
vm->apiStack = NULL;
return result;

return runInterpreter(vm, fiber);
}

ObjClosure* wrenCompileSource(WrenVM* vm, const char* module, const char* source,
Expand Down
6 changes: 5 additions & 1 deletion test/api/new_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ static void multipleInterpretCalls(WrenVM* vm)
// Handles should be valid across calls into Wren code.
WrenHandle* absMethod = wrenMakeCallHandle(otherVM, "abs");

result = wrenInterpret(otherVM, "main", "import \"random\" for Random");
correct = correct && (result == WREN_RESULT_SUCCESS);

for (int i = 0; i < 5; i++) {
// Calling `wrenEnsureSlots()` before `wrenInterpret()` should not introduce
// problems later.
wrenEnsureSlots(otherVM, 2);

result = wrenInterpret(otherVM, "main", "1 + 2");
// Calling a foreign function should succeed.
result = wrenInterpret(otherVM, "main", "Random.new(12345)");
correct = correct && (result == WREN_RESULT_SUCCESS);

wrenEnsureSlots(otherVM, 2);
Expand Down

0 comments on commit 3676a5b

Please sign in to comment.