Quirrel4.41.0

Stack operations

Moving values on the VM stack, and counting them.

These functions do not read or write values. Pushing a C value and reading one back are on Creating objects and Manipulating objects. This page covers the shape of the stack itself.

See The stack for the index convention. Every function here follows it.

void sq_push(HSQUIRRELVM v, SQInteger idx)

Pushes in the stack the value at the index idx.

void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)

Pops n elements from the stack.

void sq_poptop(HSQUIRRELVM v)

Pops 1 object from the stack.

void sq_remove(HSQUIRRELVM v, SQInteger idx)

Removes an element from an arbitrary position in the stack.

SQInteger sq_gettop(HSQUIRRELVM v)

Returns the index of the top of the stack, which is also the number of values on it.

void sq_settop(HSQUIRRELVM v, SQInteger newtop)

Forces the stack to a given size, padding with nulls when it grows.

SQRESULT sq_reservestack(HSQUIRRELVM v, SQInteger nsize)

Ensure that the stack space left is at least of a specified size.If the stack is smaller it will automatically grow. If there's a metamethod currently running the function will fail and the stack will not be resized, this situation has to be considered a "stack overflow".

SQInteger sq_cmp(HSQUIRRELVM v)

Compares the two values on top of the stack. The right operand is pushed first.

bool sq_cmpraw(HSQUIRRELVM v, HSQOBJECT &lhs, HSQOBJECT &rhs, SQInteger &res)

Compares the two values on top of the stack without consulting a _cmp metamethod.

void sq_move(HSQUIRRELVM dest, HSQUIRRELVM src, SQInteger idx)

Pushes the object at the position 'idx' of the source VM stack in the destination VM stack.