feat: add WrenErrorType enum and route runtime errors through config errorFn callback

Replace direct fprintf(stderr) calls in wrenDebugPrintStackTrace with invocations of the host-provided errorFn callback, passing WREN_ERROR_RUNTIME for the error message and WREN_ERROR_STACK_TRACE for each stack frame. Introduce the WrenErrorType enum in wren.h with WREN_ERROR_COMPILE, WREN_ERROR_RUNTIME, and WREN_ERROR_STACK_TRACE values, update the WrenErrorFn typedef to accept a type parameter, and modify reportError in cli/vm.c to switch on the error type for formatted output. Adjust wrenDebugPrintStackTrace signature to take WrenVM* instead of ObjFiber* to access the config, and update all call sites accordingly.
This commit is contained in:
Bob Nystrom
2016-03-17 14:17:03 +00:00
parent 63e462bb84
commit 7e72462d90
7 changed files with 56 additions and 12 deletions
+16 -2
View File
@@ -156,9 +156,23 @@ static void write(WrenVM* vm, const char* text)
fflush(stdout);
}
static void reportError(const char* module, int line, const char* message)
static void reportError(WrenErrorType type,
const char* module, int line, const char* message)
{
fprintf(stderr, "[%s line %d] %s\n", module, line, message);
switch (type)
{
case WREN_ERROR_COMPILE:
fprintf(stderr, "[%s line %d] %s\n", module, line, message);
break;
case WREN_ERROR_RUNTIME:
fprintf(stderr, "%s\n", message);
break;
case WREN_ERROR_STACK_TRACE:
fprintf(stderr, "[%s line %d] in %s\n", module, line, message);
break;
}
}
static void initVM()