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:
+16
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user