From a3f5b3d98fcdad26b9323bea3c3644f672a317e9 Mon Sep 17 00:00:00 2001 From: Michel Hermier Date: Sat, 11 Jul 2020 22:05:22 +0200 Subject: [PATCH] wren/vm: Allow wrenInterpret to call foreign function (complement 344d343 at fixing #730). (#764) --- src/vm/wren_vm.c | 7 ++----- test/api/new_vm.c | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index 05cf4361..ab2f3406 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -1454,12 +1454,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, diff --git a/test/api/new_vm.c b/test/api/new_vm.c index 4c50fd4a..632b93d8 100644 --- a/test/api/new_vm.c +++ b/test/api/new_vm.c @@ -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);