Add test for user data.
Also moved the VM parameter in the error callback to be first like it is in other callbacks.
This commit is contained in:
+2
-2
@@ -154,8 +154,8 @@ static void write(WrenVM* vm, const char* text)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void reportError(WrenErrorType type,
|
||||
const char* module, int line, const char* message, WrenVM* vm)
|
||||
static void reportError(WrenVM* vm, WrenErrorType type,
|
||||
const char* module, int line, const char* message)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
||||
+3
-2
@@ -96,7 +96,8 @@ typedef enum
|
||||
// Each of those has the module and line where the method or function is
|
||||
// defined and [message] is the name of the method or function.
|
||||
typedef void (*WrenErrorFn)(
|
||||
WrenErrorType type, const char* module, int line, const char* message, WrenVM* vm);
|
||||
WrenVM* vm, WrenErrorType type, const char* module, int line,
|
||||
const char* message);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -207,7 +208,7 @@ typedef struct
|
||||
// If zero, defaults to 50.
|
||||
int heapGrowthPercent;
|
||||
|
||||
// User defined state data associated with the WrenVM.
|
||||
// User-defined data associated with the VM.
|
||||
void* userData;
|
||||
|
||||
} WrenConfiguration;
|
||||
|
||||
@@ -403,8 +403,8 @@ static void printError(Parser* parser, int line, const char* label,
|
||||
length += vsprintf(message + length, format, args);
|
||||
ASSERT(length < ERROR_MESSAGE_SIZE, "Error should not exceed buffer.");
|
||||
|
||||
parser->vm->config.errorFn(WREN_ERROR_COMPILE,
|
||||
parser->module->name->value, line, message, parser->vm);
|
||||
parser->vm->config.errorFn(parser->vm, WREN_ERROR_COMPILE,
|
||||
parser->module->name->value, line, message);
|
||||
}
|
||||
|
||||
// Outputs a compile or syntax error. This also marks the compilation as having
|
||||
|
||||
+7
-4
@@ -10,13 +10,15 @@ void wrenDebugPrintStackTrace(WrenVM* vm)
|
||||
ObjFiber* fiber = vm->fiber;
|
||||
if (IS_STRING(fiber->error))
|
||||
{
|
||||
vm->config.errorFn(WREN_ERROR_RUNTIME, NULL, -1, AS_CSTRING(fiber->error), vm);
|
||||
vm->config.errorFn(vm, WREN_ERROR_RUNTIME,
|
||||
NULL, -1, AS_CSTRING(fiber->error));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Print something a little useful here. Maybe the name of the error's
|
||||
// class?
|
||||
vm->config.errorFn(WREN_ERROR_RUNTIME, NULL, -1, "[error object]", vm);
|
||||
vm->config.errorFn(vm, WREN_ERROR_RUNTIME,
|
||||
NULL, -1, "[error object]");
|
||||
}
|
||||
|
||||
for (int i = fiber->numFrames - 1; i >= 0; i--)
|
||||
@@ -34,8 +36,9 @@ void wrenDebugPrintStackTrace(WrenVM* vm)
|
||||
|
||||
// -1 because IP has advanced past the instruction that it just executed.
|
||||
int line = fn->debug->sourceLines.data[frame->ip - fn->code.data - 1];
|
||||
vm->config.errorFn(WREN_ERROR_STACK_TRACE, fn->module->name->value, line,
|
||||
fn->debug->name, vm);
|
||||
vm->config.errorFn(vm, WREN_ERROR_STACK_TRACE,
|
||||
fn->module->name->value, line,
|
||||
fn->debug->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user