forked from Mirror/wren
Fix bug #362 calling Foreign methods
I assume that invoking callForeign that the apiStack should be restored to it's original value, rather than reset to NULL.
This commit is contained in:
@ -366,6 +366,7 @@ static void bindMethod(WrenVM* vm, int methodType, int symbol,
|
||||
static void callForeign(WrenVM* vm, ObjFiber* fiber,
|
||||
WrenForeignMethodFn foreign, int numArgs)
|
||||
{
|
||||
Value* oldApiStack = vm->apiStack; /// save the current state so we can restore it when done
|
||||
vm->apiStack = fiber->stackTop - numArgs;
|
||||
|
||||
foreign(vm);
|
||||
@ -373,7 +374,7 @@ static void callForeign(WrenVM* vm, ObjFiber* fiber,
|
||||
// Discard the stack slots for the arguments and temporaries but leave one
|
||||
// for the result.
|
||||
fiber->stackTop = vm->apiStack + 1;
|
||||
vm->apiStack = NULL;
|
||||
vm->apiStack = oldApiStack; /// restore apiStack to value prior to calling foreign method
|
||||
}
|
||||
|
||||
// Handles the current fiber having aborted because of an error. Switches to
|
||||
@ -655,11 +656,12 @@ static void createForeign(WrenVM* vm, ObjFiber* fiber, Value* stack)
|
||||
ASSERT(method->type == METHOD_FOREIGN, "Allocator should be foreign.");
|
||||
|
||||
// Pass the constructor arguments to the allocator as well.
|
||||
Value* oldApiStack = vm->apiStack;
|
||||
vm->apiStack = stack;
|
||||
|
||||
method->fn.foreign(vm);
|
||||
|
||||
vm->apiStack = NULL;
|
||||
vm->apiStack = oldApiStack;
|
||||
// TODO: Check that allocateForeign was called.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user