Calls and errors
Calling a script function from C, and raising and reading errors.
A call is set up on the stack: push the closure, push its this, push the arguments, then sq_call with the count. sq_call pops what it was given and pushes the result if asked for one. See Compiling and calling for the sequence.
Errors travel the same way a script throw does. A sq_throwerror from a native can be caught by a try in the script that called it. sq_getlasterror reads the value back on the C side.
Calls a closure. Pops the arguments and the closure's this, and pushes the return value when retval asks for it. A VM suspended mid-call keeps both on the stack instead.
Resumes the generator at the top position of the stack.
Returns the name of a local in a given frame and pushes its value. Free variables are reported first, as though they sat below the real locals.
Pushes onto the stack the currently running closure.
Gets the value of the free variable of the closure at the position idx in the stack.
Throws the VM's own wrong-parameter-type error, so a native reports a bad argument the way the VM does.
Sets the last error in the virtual machine and returns the value that has to be returned by a native closure in order to trigger an exception in the virtual machine.
Pops a value from the stack sets it as the last error in the virtual machine. Returns the value that has to be returned by a native closure in order to trigger an exception in the virtual machine (aka SQ_ERROR).
Reset the last error in the virtual machine to null.
Pushes the last error in the stack.
Calls a closure and removes the caller function from the call stack. This function must be invoke from a native closure and he return value of sq_tailcall must be returned by the caller function(see example).