4.3. Stack Operations

SQInteger sq_cmp(HSQUIRRELVM v)
Parameters:
  • v (HSQUIRRELVM) – the target VM
Returns:

> 0 if obj1>obj2

Returns:

== 0 if obj1==obj2

Returns:

< 0 if obj1<obj2

compares 2 object from the stack and compares them.

SQInteger sq_gettop(HSQUIRRELVM v)
Parameters:
  • v (HSQUIRRELVM) – the target VM
Returns:

an integer representing the index of the top of the stack

returns the index of the top of the stack

void sq_pop(HSQUIRRELVM v, SQInteger nelementstopop)
Parameters:
  • v (HSQUIRRELVM) – the target VM
  • nelementstopop (SQInteger) – the number of elements to pop

pops n elements from the stack

void sq_poptop(HSQUIRRELVM v)
Parameters:
  • v (HSQUIRRELVM) – the target VM

pops 1 object from the stack

void sq_push(HSQUIRRELVM v, SQInteger idx)
Parameters:
  • v (HSQUIRRELVM) – the target VM
  • idx (SQInteger) – the index in the stack of the value that has to be pushed

pushes in the stack the value at the index idx

void sq_remove(HSQUIRRELVM v, SQInteger idx)
Parameters:
  • v (HSQUIRRELVM) – the target VM
  • idx (SQInteger) – index of the element that has to be removed

removes an element from an arbitrary position in the stack

SQRESULT sq_reservestack(HSQUIRRELVM v, SQInteger nsize)
Parameters:
  • v (HSQUIRRELVM) – the target VM
  • nsize (SQInteger) – required stack size
Returns:

a SQRESULT

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 memtamethod currently running the function will fail and the stack will not be resized, this situatuation has to be considered a “stack overflow”.

void sq_settop(HSQUIRRELVM v, SQInteger v)
Parameters:
  • v (SQInteger) – the target VM
  • v – the new top index

resize the stack, if new top is bigger then the current top the function will push nulls.