feat: add user-defined state data pointer and accessors to WrenVM

Add a `userData` void pointer field to `WrenConfiguration` and expose `wrenGetUserData`/`wrenSetUserData` functions for associating arbitrary state with a VM instance. Also update the `WrenErrorFn` signature to include the `WrenVM*` parameter, and propagate the VM pointer through all error callback invocations in the compiler, debug, and runtime paths.
This commit is contained in:
scott
2017-01-20 03:54:25 +00:00
parent 08a868ce3f
commit b2b187ab07
4 changed files with 26 additions and 5 deletions
+11 -1
View File
@@ -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