Standard library
Registering the standard modules, and the C entry points they expose to a host.
No part of the standard library is loaded automatically. A host registers the modules it wants a script to reach. This is how a sandbox is built: leave out io and system, and no script can open a file or run a command.
Each sqstd_register_*lib expects the target table on the stack. The other functions here let C code use what those modules implement: read a blob's bytes, open a file as a stream, run a regular expression.
Registration and error reporting
Most hosts want sqstd_seterrorhandlers early. Without it, an unhandled error leaves no trace.
Installs the standard error and compiler error handlers, which print the message and the call stack.
Prints the current call stack through the VM's print function.
Pushes the current call stack rendered as a string.
Renders the value of a thrown error as a string.
Push `trace` (the captured async-fault trace array) rendered as a string (SQ_ERROR when it is not an array / has no frames).
Push the live callstack if it has frames, else `trace` (the async fault's captured trace array) rendered as a string.
Throws an error built with printf-style formatting.
Blobs
Creates a blob of the given size and pushes it.
Returns the payload pointer of the blob at idx.
Returns the size of the blob at idx.
Registers the blob library into the VM.
Files and streams
Opens a file and returns a stream handle.
Reads bytes from a stream handle.
Writes bytes to a stream handle.
Moves the cursor of a stream handle.
Returns the cursor position of a stream handle.
Flushes a stream handle.
Closes a stream handle.
Reports whether a stream handle is at its end.
Pushes a script file object wrapping an open stream handle.
Returns the stream handle behind the file object at idx.
Creates the stream class that blob and file both take their methods from.
Registers the io library into the VM.
Strings and regular expressions
The sqstd_rex_* family is the regular expression engine behind string.regexp, usable directly from C.
Compiles a regular expression.
Frees a compiled regular expression.
Tests whether a whole string matches a compiled expression.
Finds the first match of a compiled expression in a string.
Finds the first match within a range of a string.
Returns how many capturing groups a compiled expression has.
Returns the range one capturing group matched.
Reports whether the last match gave up because it exhausted its backtracking budget.
Formats values from the stack with a printf-style pattern.
Pushes a string built with printf-style formatting.
Registers the string library, including the regular expressions, into the VM.
The remaining modules
Registers the datetime library into the VM.
Registers the debug library into the VM.
Registers the math library into the VM.
Publishes the process command line to script as a global.
Registers the system library into the VM.
Extras
Object-handle shortcuts that skip the stack, for reads a host does often.
Fills a function info struct from an object handle, without touching the stack.
Copies a run of floats out of an array held as an object handle.
Reads one integer element of an array held as an object handle.
Reads one float element of an array held as an object handle.