Class ssq::VM
Class List > ssq > VM
Squirrel Virtual Machine object.
- #include <vm.hpp>
Inherits the following classes: ssq::Table
Public Functions
| Type | Name | 
|---|---|
| VM (size_t stackSize, Libs::Flag flags=0x00) Creates a VM with a fixed stack size. | |
| VM (const VM & other) = delete Disabled copy constructor. | |
| VM (VM && other) Move constructor. | |
| void | addClassObj (size_t hashCode, const HSQOBJECT & obj) Add registered class object into the table of known classes. | 
| Enum | addEnum (const char * name) Adds a new enum to this table. | 
| Object | callFunc (const Function & func, const Object & env, Args &&... args) const Calls a global function. | 
| Script | compileFile (const char * path) Compiles a script from a source file. | 
| Script | compileSource (const char * source, const char * name="buffer") Compiles a script from a memory. | 
| void | debugStack () const Prints stack objects. | 
| void | destroy () Destroys the VM and all of this objects. | 
| const HSQOBJECT & | getClassObj (size_t hashCode) Get registered class object from hash code. | 
| const CompileException & | getLastCompileException () const Returns the last compilation exception. | 
| const RuntimeException & | getLastRuntimeException () const Returns the last runtime exception. | 
| SQInteger | getTop () const Returns the index of the top slot of the stack. | 
| Array | newArray () const Creates a new empty array. | 
| Array | newArray (const std::vector< T > & vector) const Creates a new array. | 
| Instance | newInstance (const Class & cls, Args &&... args) const Creates a new instance of class and call constructor with given arguments. | 
| Instance | newInstanceNoCtor (const Class & cls) const Creates a new instance of class without calling a constructor. | 
| Table | newTable () const Creates a new empty table. | 
| VM & | operator= (const VM & other) = delete Copy assingment operator. | 
| VM & | operator= (VM && other) Move assingment operator. | 
| void | registerStdlib (Libs::Flag flags) Registers standard template libraries. | 
| void | run (const Script & script) const Runs a script. | 
| void | setCompileErrorFunc (SqCompileErrorFunc compileErrorFunc) Registers compilation error function. | 
| void | setConst (const char * name, const T & value) Adds a new constant key-value pair to this table. | 
| void | setPrintFunc (SqPrintFunc printFunc, SqErrorFunc errorFunc) Registers print and error functions. | 
| void | setRuntimeErrorFunc (SqRuntimeErrorFunc runtimeErrorFunc) Registers runtime error function. | 
| void | swap (VM & other) Swaps the contents of this VM with another one. | 
| virtual | ~VM () Destructor. | 
Public Functions inherited from ssq::Table
| Type | Name | 
|---|---|
| Table () Creates empty table with null VM . | |
| Table (const Object & other) Converts Object toTable . | |
| Table (HSQUIRRELVM vm) Creates empty table. | |
| Table (const Table & other) Copy constructor. | |
| Table (Table && other) Move constructor. | |
| Class | addAbstractClass (const char * name) Adds a new abstract class type to this table. | 
| Class | addClass (const char * name, const std::function< T *(Args...)> & allocator=std::bind(&detail::defaultClassAllocator< T >), bool release=true) Adds a new class type to this table. | 
| Class | addClass (const char * name, const Class::Ctor< T(Args...)> & constructor, bool release=true) Adds a new class type to this table. | 
| Class | addClass (const char * name, const F & lambda, bool release=true) Adds a new class type to this table. | 
| Function | addFunc (const char * name, const std::function< R(Args...)> & func) Adds a new function type to this table. | 
| Function | addFunc (const char * name, const F & lambda) Adds a new lambda type to this table. | 
| Table | addTable (const char * name) Adds a new table to this table. | 
| Class | findClass (const char * name) const Finds a class in this table. | 
| Function | findFunc (const char * name) const Finds a function in this table. | 
| T | get (const char * name) | 
| Table & | operator= (const Table & other) Copy assingment operator. | 
| Table & | operator= (Table && other) Move assingment operator. | 
| void | set (const char * name, const T & value) Adds a new key-value pair to this table. | 
| size_t | size () | 
| virtual | ~Table () = default Destructor. | 
Public Functions inherited from ssq::Object
| Type | Name | 
|---|---|
| Object () Creates an empty object with null VM . | |
| Object (HSQUIRRELVM vm) Creates an empty object. | |
| Object (const Object & other) Copy constructor to copy the object reference. | |
| Object (Object && other) Move constructor. | |
| Object | find (const char * name) const Finds object within this object. | 
| const HSQUIRRELVM & | getHandle () const Returns the Squirrel virtual machine handle associated with this instance. | 
| const HSQOBJECT & | getRaw () const Returns raw Squirrel object reference. | 
| HSQOBJECT & | getRaw () Returns raw Squirrel object reference. | 
| Type | getType () const Returns the type of the object. | 
| const char * | getTypeStr () const Returns the type of the object in string format. | 
| size_t | getTypeTag () const Returns the typetag associated with this object. | 
| bool | isEmpty () const Checks if the object is empty. | 
| bool | isNull () const Returns true if the object is nullptr. | 
| Object & | operator= (const Object & other) Copy assingment operator. | 
| Object & | operator= (Object && other) Move assingment operator. | 
| void | reset () Releases the object and resets it to empty. | 
| void | swap (Object & other) Swaps two objects. | 
| T | to () const Returns an arbitary value of this object. | 
| Array | toArray () const Returns the Array value of this object. | 
| bool | toBool () const Returns the boolean value of this object. | 
| Class | toClass () const Returns the Class value of this object. | 
| float | toFloat () const Returns the float value of this object. | 
| Function | toFunction () const Returns the Function value of this object. | 
| Instance | toInstance () const Returns the Instance value of this object. | 
| int32_t | toInt () const Returns the integer value of this object. | 
| T | toPtrUnsafe () const Unsafe cast this object into any pointer of type T. | 
| std::string | toString () const Returns the string value of this object. | 
| Table | toTable () const Returns the Table value of this object. | 
| virtual | ~Object () | 
Protected Attributes inherited from ssq::Object
| Type | Name | 
|---|---|
| HSQOBJECT | obj | 
| HSQUIRRELVM | vm | 
| bool | weak | 
Public Functions Documentation
function VM [1/3]
ssq::VM::VM (
    size_t stackSize,
    Libs::Flag flags=0x00
) 
function VM [2/3]
ssq::VM::VM (
    const VM & other
) = delete
function VM [3/3]
ssq::VM::VM (
    VM && other
) 
function addClassObj
void ssq::VM::addClassObj (
    size_t hashCode,
    const HSQOBJECT & obj
) 
function addEnum
Enum ssq::VM::addEnum (
    const char * name
) 
function callFunc
template<class... Args>
inline Object ssq::VM::callFunc (
    const Function & func,
    const Object & env,
    Args &&... args
) const
Parameters:
- func The instance of a function
- args Any number of arguments
Exception:
- RuntimeException if an exception is thrown or number of arguments do not match
- TypeException if casting from Squirrel objects to C++ objects failed
function compileFile
Script ssq::VM::compileFile (
    const char * path
) 
Exception:
function compileSource
Script ssq::VM::compileSource (
    const char * source,
    const char * name="buffer"
) 
The script can be associated with a name as a second parameter. This name is used during runtime error information.
Exception:
function debugStack
void ssq::VM::debugStack () const
function destroy
void ssq::VM::destroy () 
function getClassObj
const HSQOBJECT & ssq::VM::getClassObj (
    size_t hashCode
) 
function getLastCompileException
inline const CompileException & ssq::VM::getLastCompileException () const
function getLastRuntimeException
inline const RuntimeException & ssq::VM::getLastRuntimeException () const
function getTop
SQInteger ssq::VM::getTop () const
function newArray [1/2]
inline Array ssq::VM::newArray () const
function newArray [2/2]
template<class T class T>
inline Array ssq::VM::newArray (
    const std::vector< T > & vector
) const
function newInstance
template<class... Args>
inline Instance ssq::VM::newInstance (
    const Class & cls,
    Args &&... args
) const
Parameters:
- cls The object of a class
- args Any number of arguments
Exception:
function newInstanceNoCtor
inline Instance ssq::VM::newInstanceNoCtor (
    const Class & cls
) const
Parameters:
- cls The object of a class
Exception:
function newTable
inline Table ssq::VM::newTable () const
function operator=
VM & ssq::VM::operator= (
    const VM & other
) = delete
function operator=
VM & ssq::VM::operator= (
    VM && other
) 
function registerStdlib
void ssq::VM::registerStdlib (
    Libs::Flag flags
) 
function run
void ssq::VM::run (
    const Script & script
) const
When the script runs for the first time, the contens such as class definitions are assigned to the root table (global table).
Exception:
function setCompileErrorFunc
void ssq::VM::setCompileErrorFunc (
    SqCompileErrorFunc compileErrorFunc
) 
function setConst
template<typename T typename T>
inline void ssq::VM::setConst (
    const char * name,
    const T & value
) 
function setPrintFunc
void ssq::VM::setPrintFunc (
    SqPrintFunc printFunc,
    SqErrorFunc errorFunc
) 
function setRuntimeErrorFunc
void ssq::VM::setRuntimeErrorFunc (
    SqRuntimeErrorFunc runtimeErrorFunc
) 
function swap
void ssq::VM::swap (
    VM & other
) 
function ~VM
virtual ssq::VM::~VM () 
The documentation for this class was generated from the following file include/simplesquirrel/vm.hpp