equal
deleted
inserted
replaced
5 #ifndef SQUIRREL_HPP |
5 #ifndef SQUIRREL_HPP |
6 #define SQUIRREL_HPP |
6 #define SQUIRREL_HPP |
7 |
7 |
8 class Squirrel { |
8 class Squirrel { |
9 private: |
9 private: |
10 HSQUIRRELVM vm; ///< The VirtualMachine instnace for squirrel |
10 typedef void (SQPrintFunc)(bool error_msg, const char *message); |
|
11 |
|
12 HSQUIRRELVM vm; ///< The VirtualMachine instnace for squirrel |
|
13 void *global_pointer; ///< Can be set by who ever initializes Squirrel |
|
14 SQPrintFunc *print_func; ///< Points to either NULL, or a custom print handler |
11 |
15 |
12 /** |
16 /** |
13 * The internal RunError handler. It looks up the real error and calls RunError with it. |
17 * The internal RunError handler. It looks up the real error and calls RunError with it. |
14 */ |
18 */ |
15 static SQInteger _RunError(HSQUIRRELVM vm); |
19 static SQInteger _RunError(HSQUIRRELVM vm); |
127 * Convert a Squirrel-object to an integer. |
131 * Convert a Squirrel-object to an integer. |
128 */ |
132 */ |
129 static int ObjectToInteger(HSQOBJECT *ptr) { return sq_objtointeger(ptr); } |
133 static int ObjectToInteger(HSQOBJECT *ptr) { return sq_objtointeger(ptr); } |
130 |
134 |
131 /** |
135 /** |
132 * Sets a pointer in the VM that is reasable from where ever you are, what |
136 * Sets a pointer in the VM that is reachable from where ever you are in SQ. |
133 * ever your state is. Useful to keep track of the main instance. |
137 * Useful to keep track of the main instance. |
134 */ |
138 */ |
135 void SetGlobalPointer(void *ptr) { sq_setforeignptr(this->vm, ptr); } |
139 void SetGlobalPointer(void *ptr) { this->global_pointer = ptr; } |
136 |
140 |
137 /** |
141 /** |
138 * Get the pointer as set by SetGlobalPointer. |
142 * Get the pointer as set by SetGlobalPointer. |
139 */ |
143 */ |
140 static void *GetGlobalPointer(HSQUIRRELVM vm) { return sq_getforeignptr(vm); } |
144 static void *GetGlobalPointer(HSQUIRRELVM vm) { return ((Squirrel *)sq_getforeignptr(vm))->global_pointer; } |
|
145 |
|
146 /** |
|
147 * Set a custom print function, so you can handle outputs from SQ yourself. |
|
148 */ |
|
149 void SetPrintFunction(SQPrintFunc *func) { this->print_func = func; } |
141 |
150 |
142 /** |
151 /** |
143 * Throw a Squirrel error that will be nicely displayed to the user. |
152 * Throw a Squirrel error that will be nicely displayed to the user. |
144 */ |
153 */ |
145 void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2FS(error)); } |
154 void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2FS(error)); } |