OpenTTD Source 20260311-master-g511d3794ce
Squirrel Class Reference

Public Member Functions

 Squirrel (std::string_view api_name)
 ~Squirrel ()
 Clean up the Squirrel virtual machine state.
HSQUIRRELVM GetVM ()
 Get the squirrel VM.
bool LoadScript (const std::string &script)
 Load a script.
bool LoadScript (HSQUIRRELVM vm, const std::string &script, bool in_root=true)
SQRESULT LoadFile (HSQUIRRELVM vm, const std::string &filename, SQBool printerror)
 Load a file to a given VM.
void AddMethod (std::string_view method_name, SQFUNCTION proc, std::string_view params={}, void *userdata=nullptr, int size=0, bool suspendable=false)
 Adds a function to the stack.
void AddConst (std::string_view var_name, SQInteger value)
 Adds a const to the stack.
void AddConst (std::string_view var_name, uint value)
 Adds a const to the stack.
void AddConst (std::string_view var_name, int value)
 Adds a const to the stack.
void AddConst (std::string_view var_name, const ConvertibleThroughBase auto &value)
 Adds a const to the stack.
void AddConst (std::string_view var_name, bool value)
 Adds a const to the stack.
void AddClassBegin (std::string_view class_name)
 Adds a class to the global scope.
void AddClassBegin (std::string_view class_name, std::string_view parent_class)
 Adds a class to the global scope, extending 'parent_class'.
void AddClassEnd ()
 Finishes adding a class to the global scope.
bool Resume (int suspend=-1)
 Resume a VM when it was suspended via a throw.
void ResumeError ()
 Resume the VM with an error so it prints a stack trace.
void CollectGarbage ()
 Tell the VM to do a garbage collection run.
void InsertResult (bool result)
void InsertResult (int result)
void InsertResult (uint result)
void InsertResult (ConvertibleThroughBase auto result)
bool CallMethod (HSQOBJECT instance, std::string_view method_name, HSQOBJECT *ret, int suspend)
 Call a method of an instance returning a Squirrel object.
bool CallMethod (HSQOBJECT instance, std::string_view method_name, int suspend)
 Call a method of an instance returning nothing.
bool CallStringMethod (HSQOBJECT instance, std::string_view method_name, std::string *res, int suspend)
 Call a method of an instance returning a string.
bool CallIntegerMethod (HSQOBJECT instance, std::string_view method_name, int *res, int suspend)
 Call a method of an instance returning a integer.
bool CallBoolMethod (HSQOBJECT instance, std::string_view method_name, bool *res, int suspend)
 Call a method of an instance returning a boolean.
bool MethodExists (HSQOBJECT instance, std::string_view method_name)
 Check if a method exists in an instance.
bool CreateClassInstance (const std::string &class_name, void *real_instance, HSQOBJECT *instance)
 Create a class instance.
void SetGlobalPointer (void *ptr)
 Sets a pointer in the VM that is reachable from where ever you are in SQ.
void SetPrintFunction (SQPrintFunc *func)
 Set a custom print function, so you can handle outputs from SQ yourself.
void ThrowError (std::string_view error)
 Throw a Squirrel error that will be nicely displayed to the user.
void ReleaseObject (HSQOBJECT *ptr)
 Release a SQ object.
bool IsSuspended ()
 Did the squirrel code suspend or return normally.
bool HasScriptCrashed ()
 Find out if the squirrel script made an error before.
void CrashOccurred ()
 Set the script status to crashed.
bool CanSuspend ()
 Are we allowed to suspend the squirrel script at this moment?
SQInteger GetOpsTillSuspend ()
 How many operations can we execute till suspension?
void Reset ()
 Completely reset the engine; start from scratch.
size_t GetAllocatedMemory () const noexcept
 Get number of bytes allocated by this VM.

Static Public Member Functions

static bool CreateClassInstanceVM (HSQUIRRELVM vm, const std::string &class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook, bool prepend_API_name=false)
 Creates a class instance.
static SQUserPointer GetRealInstance (HSQUIRRELVM vm, int index, std::string_view tag)
 Get the real-instance pointer.
static void GetInstance (HSQUIRRELVM vm, HSQOBJECT *ptr, int pos=1)
 Get the Squirrel-instance pointer.
static std::optional< std::string_view > ObjectToString (HSQOBJECT *ptr)
 Convert a Squirrel-object to a string.
static int ObjectToInteger (HSQOBJECT *ptr)
 Convert a Squirrel-object to an integer.
static bool ObjectToBool (HSQOBJECT *ptr)
 Convert a Squirrel-object to a bool.
static void * GetGlobalPointer (HSQUIRRELVM vm)
 Get the pointer as set by SetGlobalPointer.
static void DecreaseOps (HSQUIRRELVM vm, int amount)
 Tell the VM to remove amount ops from the number of ops till suspend.
static void IncreaseAllocatedSize (size_t bytes)
 Increase number of bytes allocated in the current script allocator scope.
static void DecreaseAllocatedSize (size_t bytes)
 Decrease number of bytes allocated in the current script allocator scope.

Static Protected Member Functions

static void CompileError (HSQUIRRELVM vm, std::string_view desc, std::string_view source, SQInteger line, SQInteger column)
 The CompileError handler.
static void RunError (HSQUIRRELVM vm, std::string_view error)
 The RunError handler.
static void PrintFunc (HSQUIRRELVM vm, std::string_view s)
 If a user runs 'print' inside a script, this function gets the params.
static void ErrorPrintFunc (HSQUIRRELVM vm, std::string_view s)
 If an error has to be print, this function is called.

Private Types

using SQPrintFunc = void (bool error_msg, std::string_view message)

Private Member Functions

std::string_view GetAPIName ()
 Get the API name.
void Initialize ()
 Perform all initialization steps to create the engine.
void Uninitialize ()
 Perform all the cleanups for the engine.

Static Private Member Functions

static SQInteger _RunError (HSQUIRRELVM vm)
 The internal RunError handler.

Private Attributes

HSQUIRRELVM vm
 The VirtualMachine instance for squirrel.
void * global_pointer
 Can be set by who ever initializes Squirrel.
SQPrintFunc * print_func
 Points to either nullptr, or a custom print handler.
bool crashed
 True if the squirrel script made an error.
int overdrawn_ops
 The amount of operations we have overdrawn.
std::string_view api_name
 Name of the API used for this squirrel.
std::unique_ptr< ScriptAllocatorallocator
 Allocator object used by this script.

Friends

class ScriptAllocatorScope
class ScriptInstance

Detailed Description

Definition at line 24 of file squirrel.hpp.

Member Typedef Documentation

◆ SQPrintFunc

using Squirrel::SQPrintFunc = void (bool error_msg, std::string_view message)
private

Definition at line 29 of file squirrel.hpp.

Constructor & Destructor Documentation

◆ Squirrel()

Squirrel::Squirrel ( std::string_view api_name)

Definition at line 531 of file squirrel.cpp.

◆ ~Squirrel()

Squirrel::~Squirrel ( )

Clean up the Squirrel virtual machine state.

Definition at line 740 of file squirrel.cpp.

References Uninitialize().

Member Function Documentation

◆ _RunError()

SQInteger Squirrel::_RunError ( HSQUIRRELVM vm)
staticprivate

The internal RunError handler.

It looks up the real error and calls RunError with it.

Parameters
vmThe virtual machine.
Returns
Always 0. Required return type due to this being passed to another function.

Definition at line 233 of file squirrel.cpp.

References RunError(), and vm.

Referenced by Initialize().

◆ AddClassBegin() [1/2]

void Squirrel::AddClassBegin ( std::string_view class_name)

Adds a class to the global scope.

Make sure to call AddClassEnd when you are done adding methods.

Parameters
class_nameThe name of the class.

Definition at line 312 of file squirrel.cpp.

References vm.

◆ AddClassBegin() [2/2]

void Squirrel::AddClassBegin ( std::string_view class_name,
std::string_view parent_class )

Adds a class to the global scope, extending 'parent_class'.

Make sure to call AddClassEnd when you are done adding methods.

Parameters
class_nameThe name of the class.
parent_classThe name of the class that is being extended.

Definition at line 321 of file squirrel.cpp.

References Debug, and vm.

◆ AddClassEnd()

void Squirrel::AddClassEnd ( )

Finishes adding a class to the global scope.

If this isn't called, no class is really created.

Definition at line 336 of file squirrel.cpp.

References vm.

◆ AddConst() [1/5]

void Squirrel::AddConst ( std::string_view var_name,
bool value )

Adds a const to the stack.

Depending on the current state this means either a const to a class or to the global space.

Parameters
var_nameThe name of the constant.
valueThe value to set the constant to.

Definition at line 303 of file squirrel.cpp.

References vm.

◆ AddConst() [2/5]

void Squirrel::AddConst ( std::string_view var_name,
const ConvertibleThroughBase auto & value )
inline

Adds a const to the stack.

Depending on the current state this means either a const to a class or to the global space.

Parameters
var_nameThe name of the constant.
valueThe value to set the constant to.

Definition at line 158 of file squirrel.hpp.

References AddConst().

Referenced by AddConst().

◆ AddConst() [3/5]

void Squirrel::AddConst ( std::string_view var_name,
int value )
inline

Adds a const to the stack.

Depending on the current state this means either a const to a class or to the global space.

Parameters
var_nameThe name of the constant.
valueThe value to set the constant to.

Definition at line 150 of file squirrel.hpp.

References AddConst().

Referenced by AddConst().

◆ AddConst() [4/5]

void Squirrel::AddConst ( std::string_view var_name,
SQInteger value )

Adds a const to the stack.

Depending on the current state this means either a const to a class or to the global space.

Parameters
var_nameThe name of the constant.
valueThe value to set the constant to.

Definition at line 294 of file squirrel.cpp.

References vm.

◆ AddConst() [5/5]

void Squirrel::AddConst ( std::string_view var_name,
uint value )
inline

Adds a const to the stack.

Depending on the current state this means either a const to a class or to the global space.

Parameters
var_nameThe name of the constant.
valueThe value to set the constant to.

Definition at line 142 of file squirrel.hpp.

References AddConst().

Referenced by AddConst().

◆ AddMethod()

void Squirrel::AddMethod ( std::string_view method_name,
SQFUNCTION proc,
std::string_view params = {},
void * userdata = nullptr,
int size = 0,
bool suspendable = false )

Adds a function to the stack.

Depending on the current state this means either a method or a global function.

Parameters
method_nameThe name of the method.
procThe actual method implementation to add.
paramsDescription of all the parameters.
userdataOptional userdata to pass onto the created closure.
sizeNumber of bytes in the user data.
suspendableWhether the method is suspendable.

Definition at line 259 of file squirrel.cpp.

References vm.

Referenced by DefSQClass< CL, ST >::DefSQAdvancedMethod(), DefSQClass< CL, ST >::DefSQAdvancedStaticMethod(), squirrel_register_global_std(), and squirrel_register_std().

◆ CallBoolMethod()

bool Squirrel::CallBoolMethod ( HSQOBJECT instance,
std::string_view method_name,
bool * res,
int suspend )

Call a method of an instance returning a boolean.

Parameters
instanceThe object to call the method on.
method_nameThe name of the method to call.
[out]resThe result of calling the method.
suspendMaximum number of operations until the method gets suspended.
Returns
false iff the script crashed or returned a wrong type.

Definition at line 452 of file squirrel.cpp.

References CallMethod(), and ObjectToBool().

Referenced by AIInfo::Constructor(), and GameInfo::Constructor().

◆ CallIntegerMethod()

bool Squirrel::CallIntegerMethod ( HSQOBJECT instance,
std::string_view method_name,
int * res,
int suspend )

Call a method of an instance returning a integer.

Parameters
instanceThe object to call the method on.
method_nameThe name of the method to call.
[out]resThe result of calling the method.
suspendMaximum number of operations until the method gets suspended.
Returns
false iff the script crashed or returned a wrong type.

Definition at line 443 of file squirrel.cpp.

References CallMethod(), and ObjectToInteger().

Referenced by AIInfo::Constructor(), GameInfo::Constructor(), and ScriptInfo::Constructor().

◆ CallMethod() [1/2]

bool Squirrel::CallMethod ( HSQOBJECT instance,
std::string_view method_name,
HSQOBJECT * ret,
int suspend )

Call a method of an instance returning a Squirrel object.

Parameters
instanceThe object to call the method on.
method_nameThe name of the method to call.
[out]retThe object to write the method result to.
suspendMaximum number of operations until the method gets suspended.
Returns
false iff the script crashed or returned a wrong type.

Definition at line 397 of file squirrel.cpp.

References crashed, Debug, IsSuspended(), and vm.

Referenced by CallBoolMethod(), CallIntegerMethod(), and CallStringMethod().

◆ CallMethod() [2/2]

bool Squirrel::CallMethod ( HSQOBJECT instance,
std::string_view method_name,
int suspend )
inline

Call a method of an instance returning nothing.

Parameters
instanceThe object to call the method on.
method_nameThe name of the method to call.
suspendMaximum number of operations until the method gets suspended.
Returns
false iff the script crashed or returned a wrong type.

Definition at line 228 of file squirrel.hpp.

References CallMethod().

Referenced by CallMethod().

◆ CallStringMethod()

bool Squirrel::CallStringMethod ( HSQOBJECT instance,
std::string_view method_name,
std::string * res,
int suspend )

Call a method of an instance returning a string.

Parameters
instanceThe object to call the method on.
method_nameThe name of the method to call.
[out]resThe result of calling the method.
suspendMaximum number of operations until the method gets suspended.
Returns
false iff the script crashed or returned a wrong type.

Definition at line 431 of file squirrel.cpp.

References CallMethod(), ObjectToString(), and StrMakeValid().

Referenced by AIInfo::Constructor(), GameInfo::Constructor(), and ScriptInfo::Constructor().

◆ CanSuspend()

bool Squirrel::CanSuspend ( )

Are we allowed to suspend the squirrel script at this moment?

Returns
true iff it is safe to suspend the script.

Definition at line 811 of file squirrel.cpp.

◆ CollectGarbage()

void Squirrel::CollectGarbage ( )

Tell the VM to do a garbage collection run.

Definition at line 391 of file squirrel.cpp.

References vm.

◆ CompileError()

void Squirrel::CompileError ( HSQUIRRELVM vm,
std::string_view desc,
std::string_view source,
SQInteger line,
SQInteger column )
staticprotected

The CompileError handler.

Parameters
vmThe virtual machine the error occurred for.
descA description of the error.
sourceThe file the error occurred in.
lineThe line the error was in.
columnThe column the error was in.

Definition at line 185 of file squirrel.cpp.

References crashed, Debug, print_func, and vm.

Referenced by Initialize().

◆ CrashOccurred()

void Squirrel::CrashOccurred ( )

Set the script status to crashed.

Definition at line 806 of file squirrel.cpp.

References crashed.

◆ CreateClassInstance()

bool Squirrel::CreateClassInstance ( const std::string & class_name,
void * real_instance,
HSQOBJECT * instance )

Create a class instance.

Exactly the same as CreateClassInstanceVM, only callable without instance of Squirrel.

Parameters
class_nameThe name of the class of which we create an instance.
real_instanceThe instance to the real class, if it represents a real class.
instanceReturning value with the pointer to the instance.
Returns
true iff the class could be created.

Definition at line 508 of file squirrel.cpp.

References CreateClassInstanceVM(), and vm.

◆ CreateClassInstanceVM()

bool Squirrel::CreateClassInstanceVM ( HSQUIRRELVM vm,
const std::string & class_name,
void * real_instance,
HSQOBJECT * instance,
SQRELEASEHOOK release_hook,
bool prepend_API_name = false )
static

Creates a class instance.

Parameters
vmThe VM to create the class instance for
class_nameThe name of the class of which we create an instance.
real_instanceThe instance to the real class, if it represents a real class.
instanceReturning value with the pointer to the instance.
release_hookOptional param to give a release hook.
prepend_API_nameOptional parameter; if true, the class_name is prefixed with the current API name.
Returns
False if creating failed.

Definition at line 461 of file squirrel.cpp.

References Debug, GetAPIName(), and vm.

Referenced by CreateClassInstance().

◆ DecreaseAllocatedSize()

void Squirrel::DecreaseAllocatedSize ( size_t bytes)
static

Decrease number of bytes allocated in the current script allocator scope.

Parameters
bytesNumber of bytes to decrease.

Definition at line 828 of file squirrel.cpp.

◆ DecreaseOps()

void Squirrel::DecreaseOps ( HSQUIRRELVM vm,
int amount )
static

Tell the VM to remove amount ops from the number of ops till suspend.

Parameters
vmThe virtual machine to change.
amountThe amount of operations to change by.

Definition at line 791 of file squirrel.cpp.

References vm.

Referenced by ScriptInstance::Pause().

◆ ErrorPrintFunc()

void Squirrel::ErrorPrintFunc ( HSQUIRRELVM vm,
std::string_view s )
staticprotected

If an error has to be print, this function is called.

Parameters
vmThe virtual machine to print for.
sThe eroror text to print.

Definition at line 200 of file squirrel.cpp.

References vm.

Referenced by RunError().

◆ GetAllocatedMemory()

size_t Squirrel::GetAllocatedMemory ( ) const
noexcept

Get number of bytes allocated by this VM.

Returns
The size in bytes.

Definition at line 178 of file squirrel.cpp.

◆ GetAPIName()

std::string_view Squirrel::GetAPIName ( )
inlineprivate

Get the API name.

Returns
The name of the API (AI/GS).

Definition at line 50 of file squirrel.hpp.

Referenced by CreateClassInstanceVM(), GetRealInstance(), and LoadFile().

◆ GetGlobalPointer()

void * Squirrel::GetGlobalPointer ( HSQUIRRELVM vm)
inlinestatic

Get the pointer as set by SetGlobalPointer.

Parameters
vmThe virtual machine to get the pointer for.
Returns
The pointer previously set.

Definition at line 343 of file squirrel.hpp.

References vm.

Referenced by ScriptInfo::Constructor().

◆ GetInstance()

void Squirrel::GetInstance ( HSQUIRRELVM vm,
HSQOBJECT * ptr,
int pos = 1 )
inlinestatic

Get the Squirrel-instance pointer.

Note
This will only work just after a function-call from within Squirrel to your C++ function.
Parameters
vmThe virtual machine to work in.
[out]ptrThe pointer to write the object to.
posThe position of the stack.

Definition at line 308 of file squirrel.hpp.

References vm.

Referenced by ScriptInfo::Constructor(), SQConvert::DefSQAdvancedNonStaticCallback(), and SQConvert::DefSQNonStaticCallback().

◆ GetOpsTillSuspend()

SQInteger Squirrel::GetOpsTillSuspend ( )

How many operations can we execute till suspension?

Returns
The number of operations left.

Definition at line 817 of file squirrel.cpp.

Referenced by ScriptInstance::GetOpsTillSuspend().

◆ GetRealInstance()

SQUserPointer Squirrel::GetRealInstance ( HSQUIRRELVM vm,
int index,
std::string_view tag )
static

Get the real-instance pointer.

Note
This will only work just after a function-call from within Squirrel to your C++ function.
Parameters
vmThe virtual machine to work in.
indexThe location on the stack. A negative value is the location from the top.
tagName of the class without the Script/AI/GS moniker.
Returns
The pointer.

Definition at line 514 of file squirrel.cpp.

References GetAPIName(), and vm.

Referenced by ScriptInstance::SaveObject().

◆ GetVM()

HSQUIRRELVM Squirrel::GetVM ( )
inline

Get the squirrel VM.

Try to avoid using this.

Returns
Our virtual machine.

Definition at line 97 of file squirrel.hpp.

Referenced by ScriptInstance::CallLoad(), ScriptInstance::LoadOnStack(), RegisterGameTranslation(), and squirrel_register_std().

◆ HasScriptCrashed()

bool Squirrel::HasScriptCrashed ( )

Find out if the squirrel script made an error before.

Returns
true iff CrashOccurred has been called.

Definition at line 801 of file squirrel.cpp.

References crashed.

◆ IncreaseAllocatedSize()

void Squirrel::IncreaseAllocatedSize ( size_t bytes)
static

Increase number of bytes allocated in the current script allocator scope.

Parameters
bytesNumber of bytes to increase.

Definition at line 822 of file squirrel.cpp.

◆ Initialize()

void Squirrel::Initialize ( )
private

Perform all initialization steps to create the engine.

Definition at line 537 of file squirrel.cpp.

References _RunError(), CompileError(), crashed, global_pointer, overdrawn_ops, print_func, PrintFunc(), squirrel_register_global_std(), and vm.

Referenced by Reset().

◆ InsertResult() [1/4]

void Squirrel::InsertResult ( bool result)

Definition at line 769 of file squirrel.cpp.

◆ InsertResult() [2/4]

void Squirrel::InsertResult ( ConvertibleThroughBase auto result)
inline

Definition at line 209 of file squirrel.hpp.

◆ InsertResult() [3/4]

void Squirrel::InsertResult ( int result)

Definition at line 780 of file squirrel.cpp.

◆ InsertResult() [4/4]

void Squirrel::InsertResult ( uint result)
inline

Definition at line 208 of file squirrel.hpp.

◆ IsSuspended()

bool Squirrel::IsSuspended ( )

Did the squirrel code suspend or return normally.

Returns
True if the function suspended.

Definition at line 796 of file squirrel.cpp.

Referenced by CallMethod().

◆ LoadFile()

SQRESULT Squirrel::LoadFile ( HSQUIRRELVM vm,
const std::string & filename,
SQBool printerror )

Load a file to a given VM.

Parameters
vmThe virtual machine to load in.
filenameThe file to open.
printerrorWhether to print errors, or completely ignore them.
Returns
0 when the file could be loaded, otherwise another number denoting an error.

Definition at line 643 of file squirrel.cpp.

References AI_DIR, AI_LIBRARY_DIR, FioFOpenFile(), GAME_DIR, GAME_LIBRARY_DIR, GetAPIName(), and vm.

◆ LoadScript() [1/2]

bool Squirrel::LoadScript ( const std::string & script)

Load a script.

Parameters
scriptThe full script-name to load.
Returns
False if loading failed.

Definition at line 734 of file squirrel.cpp.

References LoadScript().

Referenced by LoadScript(), and SquirrelStd::require().

◆ LoadScript() [2/2]

bool Squirrel::LoadScript ( HSQUIRRELVM vm,
const std::string & script,
bool in_root = true )

Definition at line 710 of file squirrel.cpp.

◆ MethodExists()

bool Squirrel::MethodExists ( HSQOBJECT instance,
std::string_view method_name )

Check if a method exists in an instance.

Parameters
instanceThe object to check.
method_nameThe method to look for.
Returns
true iff the object has the method.

Definition at line 344 of file squirrel.cpp.

References crashed, and vm.

Referenced by ScriptInstance::CallLoad(), AIInfo::Constructor(), GameInfo::Constructor(), and ScriptInfo::Constructor().

◆ ObjectToBool()

bool Squirrel::ObjectToBool ( HSQOBJECT * ptr)
inlinestatic

Convert a Squirrel-object to a bool.

Parameters
ptrThe object to convert.
Returns
A boolean.

Definition at line 329 of file squirrel.hpp.

Referenced by CallBoolMethod().

◆ ObjectToInteger()

int Squirrel::ObjectToInteger ( HSQOBJECT * ptr)
inlinestatic

Convert a Squirrel-object to an integer.

Parameters
ptrThe object to convert.
Returns
An integer.

Definition at line 322 of file squirrel.hpp.

Referenced by CallIntegerMethod().

◆ ObjectToString()

std::optional< std::string_view > Squirrel::ObjectToString ( HSQOBJECT * ptr)
inlinestatic

Convert a Squirrel-object to a string.

Parameters
ptrThe object to convert.
Returns
The std::string_view or std::nullopt.

Definition at line 315 of file squirrel.hpp.

Referenced by CallStringMethod().

◆ PrintFunc()

void Squirrel::PrintFunc ( HSQUIRRELVM vm,
std::string_view s )
staticprotected

If a user runs 'print' inside a script, this function gets the params.

Parameters
vmThe virtual machine to print for.
sThe text to print.

Definition at line 248 of file squirrel.cpp.

References vm.

Referenced by Initialize().

◆ ReleaseObject()

void Squirrel::ReleaseObject ( HSQOBJECT * ptr)
inline

Release a SQ object.

Parameters
ptrThe object to release.

Definition at line 361 of file squirrel.hpp.

Referenced by ScriptInstance::ReleaseSQObject().

◆ Reset()

void Squirrel::Reset ( )

Completely reset the engine; start from scratch.

Definition at line 763 of file squirrel.cpp.

References Initialize(), and Uninitialize().

◆ Resume()

bool Squirrel::Resume ( int suspend = -1)

Resume a VM when it was suspended via a throw.

Parameters
suspendThe number of opcodes that are allowed before suspending.
Returns
true iff the VM is still alive.

Definition at line 362 of file squirrel.cpp.

References crashed, overdrawn_ops, and vm.

◆ ResumeError()

void Squirrel::ResumeError ( )

Resume the VM with an error so it prints a stack trace.

Definition at line 384 of file squirrel.cpp.

References crashed, and vm.

◆ RunError()

void Squirrel::RunError ( HSQUIRRELVM vm,
std::string_view error )
staticprotected

The RunError handler.

Parameters
vmThe virtual machine the error occurred for.
errorA description of the error.

Definition at line 211 of file squirrel.cpp.

References ErrorPrintFunc(), print_func, and vm.

Referenced by _RunError().

◆ SetGlobalPointer()

void Squirrel::SetGlobalPointer ( void * ptr)
inline

Sets a pointer in the VM that is reachable from where ever you are in SQ.

Useful to keep track of the main instance.

Parameters
ptrArbitrary pointer.

Definition at line 336 of file squirrel.hpp.

◆ SetPrintFunction()

void Squirrel::SetPrintFunction ( SQPrintFunc * func)
inline

Set a custom print function, so you can handle outputs from SQ yourself.

Parameters
funcThe print function.

Definition at line 349 of file squirrel.hpp.

◆ ThrowError()

void Squirrel::ThrowError ( std::string_view error)
inline

Throw a Squirrel error that will be nicely displayed to the user.

Parameters
errorThe error to show to the user.

Definition at line 355 of file squirrel.hpp.

◆ Uninitialize()

void Squirrel::Uninitialize ( )
private

Perform all the cleanups for the engine.

Definition at line 745 of file squirrel.cpp.

Referenced by Reset(), and ~Squirrel().

◆ ScriptAllocatorScope

friend class ScriptAllocatorScope
friend

Definition at line 25 of file squirrel.hpp.

◆ ScriptInstance

friend class ScriptInstance
friend

Definition at line 26 of file squirrel.hpp.

Field Documentation

◆ allocator

std::unique_ptr<ScriptAllocator> Squirrel::allocator
private

Allocator object used by this script.

Definition at line 37 of file squirrel.hpp.

◆ api_name

std::string_view Squirrel::api_name
private

Name of the API used for this squirrel.

Definition at line 36 of file squirrel.hpp.

◆ crashed

bool Squirrel::crashed
private

True if the squirrel script made an error.

Definition at line 34 of file squirrel.hpp.

Referenced by CallMethod(), CompileError(), CrashOccurred(), HasScriptCrashed(), Initialize(), MethodExists(), Resume(), and ResumeError().

◆ global_pointer

void* Squirrel::global_pointer
private

Can be set by who ever initializes Squirrel.

Definition at line 32 of file squirrel.hpp.

Referenced by Initialize().

◆ overdrawn_ops

int Squirrel::overdrawn_ops
private

The amount of operations we have overdrawn.

Definition at line 35 of file squirrel.hpp.

Referenced by Initialize(), and Resume().

◆ print_func

SQPrintFunc* Squirrel::print_func
private

Points to either nullptr, or a custom print handler.

Definition at line 33 of file squirrel.hpp.

Referenced by CompileError(), Initialize(), and RunError().

◆ vm


The documentation for this class was generated from the following files: