3.5. Calls

SQRESULT sq_call(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool invoke_err_handler)
Parameters
  • v (HSQUIRRELVM) – the target VM

  • params (SQInteger) – number of parameters of the function

  • retval (SQBool) – if true the function will push the return value in the stack

  • invoke_err_handler (SQBool) – if true, if a runtime error occurs during the execution of the call, the vm will invoke the error handler.

Returns

a SQRESULT

calls a closure or a native closure. The function pops all the parameters and leave the closure in the stack; if retval is true the return value of the closure is pushed. If the execution of the function is suspended through sq_suspendvm(), the closure and the arguments will not be automatically popped from the stack.

When using to create an instance, push a dummy parameter to be filled with the newly-created instance for the constructor’s ‘this’ parameter.

SQRESULT sq_getcallee(HSQUIRRELVM v)
Parameters
  • v (HSQUIRRELVM) – the target VM

Returns

a SQRESULT

push in the stack the currently running closure.

SQRESULT sq_getlasterror(HSQUIRRELVM v)
Parameters
  • v (HSQUIRRELVM) – the target VM

Returns

a SQRESULT

Remarks

the pushed error descriptor can be any valid quirrel type.

pushes the last error in the stack.

const SQChar *sq_getlocal(HSQUIRRELVM v, SQUnsignedInteger level, SQUnsignedInteger nseq)
Parameters
  • v (HSQUIRRELVM) – the target VM

  • level (SQUnsignedInteger) – the function index in the calls stack, 0 is the current function

  • nseq (SQUnsignedInteger) – the index of the local variable in the stack frame (0 is ‘this’)

Returns

the name of the local variable if a variable exists at the given level/seq otherwise NULL.

Returns the name of a local variable given stackframe and sequence in the stack and pushes is current value. Free variables are treated as local variables, by sq_getlocal(), and will be returned as they would be at the base of the stack, just before the real local variables.

void sq_reseterror(HSQUIRRELVM v)
Parameters
  • v (HSQUIRRELVM) – the target VM

reset the last error in the virtual machine to null

SQRESULT sq_resume(HSQUIRRELVM v, SQBool retval, SQBool invoke_err_handler)
Parameters
  • v (HSQUIRRELVM) – the target VM

  • retval (SQBool) – if true the function will push the return value in the stack

  • invoke_err_handler (SQBool) – if true, if a runtime error occurs during the execution of the call, the vm will invoke the error handler.

Returns

a SQRESULT

Remarks

if retval != 0 the return value of the generator is pushed.

resumes the generator at the top position of the stack.

SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)
Parameters
  • v (HSQUIRRELVM) – the target VM

  • params (SQInteger) –

    number of parameters of the function

    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).

.eg

SQInteger tailcall_something_example(HSQUIRRELVM v)
{
            //push closure and parameters here
            ...
    return sq_tailcall(v,2);
}
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
Parameters
  • v (HSQUIRRELVM) – the target VM

  • err (const SQChar*) – the description of the error that has to be thrown

Returns

the value that has to be returned by a native closure in order to throw an exception in the virtual machine.

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.

SQRESULT sq_throwobject(HSQUIRRELVM v)
Parameters
  • v (HSQUIRRELVM) – the target VM

Returns

the value that has to be returned by a native closure in order to throw 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).