wren/vm: Allow wrenInterpret to call foreign function (complement 344d343 at fixing #730). (#764)

This commit is contained in:
Michel Hermier
2020-07-11 22:05:22 +02:00
committed by GitHub
parent da091e250c
commit a3f5b3d98f
2 changed files with 7 additions and 6 deletions

View File

@ -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,

View File

@ -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);