feat: add WrenErrorFn callback to WrenConfiguration for custom error reporting
- Add `WrenErrorFn` typedef in wren.h accepting module, line, and message parameters - Include `errorFn` slot in `WrenConfiguration` struct with documentation comment - Initialize `errorFn` to NULL in `wrenInitConfiguration()` in wren_vm.c - Replace direct `fprintf(stderr, ...)` in wren_compiler.c with call to `parser->vm->config.errorFn()` - Add guard in wren_compiler.c to skip error reporting when `errorFn` is NULL - Implement `reportError()` in cli/vm.c that writes formatted errors to stderr - Wire `reportError` into config during `initVM()` in cli/vm.c
This commit is contained in:
@@ -58,6 +58,9 @@ typedef WrenForeignMethodFn (*WrenBindForeignMethodFn)(WrenVM* vm,
|
||||
// Displays a string of text to the user.
|
||||
typedef void (*WrenWriteFn)(WrenVM* vm, const char* text);
|
||||
|
||||
// Reports an error to the user.
|
||||
typedef void (*WrenErrorFn)(const char* module, int line, const char* message);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// The callback invoked when the foreign object is created.
|
||||
@@ -126,6 +129,13 @@ typedef struct
|
||||
//
|
||||
// If this is `NULL`, Wren discards any printed text.
|
||||
WrenWriteFn writeFn;
|
||||
|
||||
// The callback Wren uses to report errors.
|
||||
//
|
||||
// When an error occurs, this will be called with the module name, line
|
||||
// number, and an error message. If this is `NULL`, Wren doesn't report any
|
||||
// errors.
|
||||
WrenErrorFn errorFn;
|
||||
|
||||
// The number of bytes Wren will allocate before triggering the first garbage
|
||||
// collection.
|
||||
|
||||
Reference in New Issue
Block a user