Add wrenAbortFiber().

Thanks, @underscorediscovery!
This commit is contained in:
Bob Nystrom
2016-06-09 19:14:21 -07:00
parent 8657a42c21
commit 59e9eb127e
8 changed files with 55 additions and 1 deletions
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <string.h>
#include "error.h"
static void runtimeError(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
wrenSetSlotString(vm, 0, "Error!");
wrenAbortFiber(vm, 0);
}
WrenForeignMethodFn errorBindMethod(const char* signature)
{
if (strcmp(signature, "static Error.runtimeError") == 0) return runtimeError;
return NULL;
}
+3
View File
@@ -0,0 +1,3 @@
#include "wren.h"
WrenForeignMethodFn errorBindMethod(const char* signature);
+12
View File
@@ -0,0 +1,12 @@
class Error {
foreign static runtimeError
}
var fiber = Fiber.new {
Error.runtimeError
}
var error = fiber.try()
System.print(error) // expect: Error!
System.print(fiber.isDone) // expect: true
System.print(fiber.error) // expect: Error!
+4
View File
@@ -6,6 +6,7 @@
#include "benchmark.h"
#include "call.h"
#include "error.h"
#include "get_variable.h"
#include "foreign_class.h"
#include "handle.h"
@@ -35,6 +36,9 @@ static WrenForeignMethodFn bindForeignMethod(
method = benchmarkBindMethod(fullName);
if (method != NULL) return method;
method = errorBindMethod(fullName);
if (method != NULL) return method;
method = getVariableBindMethod(fullName);
if (method != NULL) return method;