feat: add userData field and pass WrenVM* to error callback
Extend WrenConfiguration with a void* userData field for attaching arbitrary state to a VM instance. Add wrenGetUserData and wrenSetUserData accessor functions. Modify the WrenErrorFn typedef and all call sites (compiler, debug, VM) to pass the WrenVM pointer as the final argument, enabling error handlers to access VM context.
This commit is contained in:
+11
-1
@@ -96,7 +96,7 @@ 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);
|
||||
WrenErrorType type, const char* module, int line, const char* message, WrenVM* vm);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -206,6 +206,10 @@ typedef struct
|
||||
//
|
||||
// If zero, defaults to 50.
|
||||
int heapGrowthPercent;
|
||||
|
||||
// User defined state data associated with the WrenVM.
|
||||
void* userData;
|
||||
|
||||
} WrenConfiguration;
|
||||
|
||||
typedef enum
|
||||
@@ -447,4 +451,10 @@ void wrenGetVariable(WrenVM* vm, const char* module, const char* name,
|
||||
// runtime error object.
|
||||
void wrenAbortFiber(WrenVM* vm, int slot);
|
||||
|
||||
// Returns the user data associated with the WrenVM.
|
||||
void* wrenGetUserData(WrenVM* vm);
|
||||
|
||||
// Sets user data associated with the WrenVM.
|
||||
void wrenSetUserData(WrenVM* vm, void* userData);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user