VM, memory and watchdog
Creating a VM, its allocator, and the watchdog that stops a runaway script.
Virtual machine
A host may hold any number of VMs. Each one made with sq_open must be closed with sq_close. sq_newthread makes a friend VM that shares the parent's globals and registry; see Embedding Quirrel.
Creates a VM with its own execution stack, globals and registry.
Creates a friend VM that shares the given VM's globals and registry, and pushes it as a thread object. This is what a script thread is.
Pops a closure or native closure from the stack and sets it as the runtime error handler.
Returns a handle to the VM's current error handler.
Releases a Quirrel VM and all related friend VMs.
Sets the foreign pointer of a certain VM instance. The foreign pointer is an arbitrary user defined pointer associated to a VM (by default is value id 0). This pointer is ignored by the VM.
Returns the foreign pointer of a VM instance.
Sets the release hook of a certain VM instance. The release hook is invoked when the VM is destroyed. The userpointer passed to the function is the VM foreignpointer (see sq_setforeignpointer()).
Returns the release hook of a VM instance.
Sets the print function of the virtual machine. This function is used by the built-in function 'print()' to output text.
Returns the current print function of the given Virtual machine. (see sq_setprintfunc()).
Returns the current error function of the given Virtual machine. (see sq_setprintfunc()).
Suspends the execution of the specified VM.
Wake up the execution a previously suspended virtual machine.
Returns the execution state of a virtual machine.
Registers the base library into the VM's root table.
Registers the built-in type classes, which is what gives every value its methods.
Memory allocation
The VM routes its allocations through these functions. A host with its own heap can supply one at build time and account for what the scripts use.
Allocates through the VM's allocator.
Resizes a block allocated through the VM's allocator.
Frees a block allocated through the VM's allocator.
Watchdog
The watchdog makes an untrusted or buggy script safe to run. The interpreter loop asks the hook periodically whether it may continue, and stops the script when the answer is no. It needs no second thread.
A hook of your own outranks a timeout the script itself can move. The sandbox on this site relies on this.
Installs the callback the VM asks whether the running script may continue. Returns the previous one.
Restarts the watchdog's clock, for a native that is legitimately slow.
Sets how long a script may run before the watchdog stops it.