25 typedef void (SQPrintFunc)(
bool error_msg,
const SQChar *message);
37 static SQInteger
_RunError(HSQUIRRELVM vm);
53 static void CompileError(HSQUIRRELVM vm,
const SQChar *desc,
const SQChar *source, SQInteger line, SQInteger column);
63 static void PrintFunc(HSQUIRRELVM vm,
const SQChar *s, ...);
85 bool LoadScript(HSQUIRRELVM vm,
const char *script,
bool in_root =
true);
90 SQRESULT
LoadFile(HSQUIRRELVM vm,
const char *filename, SQBool printerror);
96 void AddMethod(
const char *method_name, SQFUNCTION proc, uint nparam = 0,
const char *params = NULL,
void *userdata = NULL,
int size = 0);
102 void AddConst(
const char *var_name,
int value);
114 void AddConst(
const char *var_name,
bool value);
126 void AddClassBegin(
const char *class_name,
const char *parent_class);
137 bool Resume(
int suspend = -1);
149 void InsertResult(
bool result);
150 void InsertResult(
int result);
151 void InsertResult(uint result) { this->InsertResult((
int)result); }
157 bool CallMethod(HSQOBJECT instance,
const char *method_name, HSQOBJECT *ret,
int suspend);
158 bool CallMethod(HSQOBJECT instance,
const char *method_name,
int suspend) {
return this->
CallMethod(instance, method_name, NULL, suspend); }
159 bool CallStringMethodStrdup(HSQOBJECT instance,
const char *method_name,
const char **res,
int suspend);
160 bool CallIntegerMethod(HSQOBJECT instance,
const char *method_name,
int *res,
int suspend);
161 bool CallBoolMethod(HSQOBJECT instance,
const char *method_name,
bool *res,
int suspend);
166 bool MethodExists(HSQOBJECT instance,
const char *method_name);
178 static bool CreateClassInstanceVM(HSQUIRRELVM vm,
const char *class_name,
void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook,
bool prepend_API_name =
false);
183 bool CreateClassInstance(
const char *class_name,
void *real_instance, HSQOBJECT *instance);
190 static bool GetRealInstance(HSQUIRRELVM vm, SQUserPointer *ptr) {
return SQ_SUCCEEDED(sq_getinstanceup(vm, 1, ptr, 0)); }
197 static bool GetInstance(HSQUIRRELVM vm, HSQOBJECT *ptr,
int pos = 1) { sq_getclass(vm, pos); sq_getstackobj(vm, pos, ptr); sq_pop(vm, 1);
return true; }
202 static const char *
ObjectToString(HSQOBJECT *ptr) {
return sq_objtostring(ptr); }
212 static bool ObjectToBool(HSQOBJECT *ptr) {
return sq_objtobool(ptr) == 1; }
233 void ThrowError(
const char *error) { sq_throwerror(this->vm, error); }
243 static void DecreaseOps(HSQUIRRELVM vm,
int amount);
static bool GetRealInstance(HSQUIRRELVM vm, SQUserPointer *ptr)
Get the real-instance pointer.
static const char * ObjectToString(HSQOBJECT *ptr)
Convert a Squirrel-object to a string.
static void PrintFunc(HSQUIRRELVM vm, const SQChar *s,...)
If a user runs 'print' inside a script, this function gets the params.
bool HasScriptCrashed()
Find out if the squirrel script made an error before.
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam=0, const char *params=NULL, void *userdata=NULL, int size=0)
Adds a function to the stack.
void * global_pointer
Can be set by who ever initializes Squirrel.
void ThrowError(const char *error)
Throw a Squirrel error that will be nicely displayed to the user.
bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend)
Call a method of an instance, in various flavors.
static void CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
The CompileError handler.
void CollectGarbage()
Tell the VM to do a garbage collection run.
SQInteger GetOpsTillSuspend()
How many operations can we execute till suspension?
static bool GetInstance(HSQUIRRELVM vm, HSQOBJECT *ptr, int pos=1)
Get the Squirrel-instance pointer.
static SQInteger _RunError(HSQUIRRELVM vm)
The internal RunError handler.
void CrashOccurred()
Set the script status to crashed.
static void DecreaseOps(HSQUIRRELVM vm, int amount)
Tell the VM to remove amount ops from the number of ops till suspend.
bool CreateClassInstance(const char *class_name, void *real_instance, HSQOBJECT *instance)
Exactly the same as CreateClassInstanceVM, only callable without instance of Squirrel.
The script is for AI scripts.
static void * GetGlobalPointer(HSQUIRRELVM vm)
Get the pointer as set by SetGlobalPointer.
bool crashed
True if the squirrel script made an error.
const char * GetAPIName()
Get the API name.
ScriptType
The type of script we're working with, i.e.
static bool ObjectToBool(HSQOBJECT *ptr)
Convert a Squirrel-object to a bool.
The script is for Game scripts.
void ResumeError()
Resume the VM with an error so it prints a stack trace.
int overdrawn_ops
The amount of operations we have overdrawn.
static bool CreateClassInstanceVM(HSQUIRRELVM vm, const char *class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook, bool prepend_API_name=false)
Creates a class instance.
bool IsSuspended()
Did the squirrel code suspend or return normally.
HSQUIRRELVM GetVM()
Get the squirrel VM.
static int ObjectToInteger(HSQOBJECT *ptr)
Convert a Squirrel-object to an integer.
void Reset()
Completely reset the engine; start from scratch.
bool CanSuspend()
Are we allowed to suspend the squirrel script at this moment?
void SetGlobalPointer(void *ptr)
Sets a pointer in the VM that is reachable from where ever you are in SQ.
void AddConst(const char *var_name, int value)
Adds a const to the stack.
bool MethodExists(HSQOBJECT instance, const char *method_name)
Check if a method exists in an instance.
SQRESULT LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printerror)
Load a file to a given VM.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void AddClassBegin(const char *class_name)
Adds a class to the global scope.
void AddConst(const char *var_name, uint value)
Adds a const to the stack.
HSQUIRRELVM vm
The VirtualMachine instance for squirrel.
static void RunError(HSQUIRRELVM vm, const SQChar *error)
The RunError handler.
const char * APIName
Name of the API used for this squirrel.
bool LoadScript(const char *script)
Load a script.
void Uninitialize()
Perform all the cleanups for the engine.
void ReleaseObject(HSQOBJECT *ptr)
Release a SQ object.
void AddClassEnd()
Finishes adding a class to the global scope.
SQPrintFunc * print_func
Points to either NULL, or a custom print handler.
static void ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s,...)
If an error has to be print, this function is called.
void Initialize()
Perform all initialization steps to create the engine.
bool Resume(int suspend=-1)
Resume a VM when it was suspended via a throw.
void SetPrintFunction(SQPrintFunc *func)
Set a custom print function, so you can handle outputs from SQ yourself.