Squirrel native dev lives and dies by the stack, so here are some notes on the effect each function has on the stack.

NOTE: SQUserPointer’s are noted as void*’s (since that’s what they really are).

Virtual Machine


Stack 0

Stack ?? (depends on args: 0, -1, +1, or both)

Stack +1

Stack -1

Pops a value and sets it to the value found on the stack.

Compiler


If (successful) Stack +1 else Stack 0

Use sq_gettop(vm) to check if it was a success.

Stack Operations


Stack 0

Stack +1

Stack -1

Stack +N or -N

Stack -N

Object Creation and Handling


Stack +1

Notably sq_typeof() also returns values like OT_FLOAT, but specific info can be retrieved from the stack. DO NOT FORGET ABOUT THE STACK! POP IF UNUSED!

Stack ?? (+1, or optionally 0)

Stack -N and +1

Stack 0

SQR – shorthand for SQRESULT (for use with SQ_SUCCESS() and SQ_FAILURE()).

Stack -1 then +1 (effectively 0)

Stack -1

Member names are actual members of classes. For example, “x” in a vec2 class. sq_setbyhandle and sq_getbyhandle are used to read/write data to class members referenced by the Member Handle. Complicated yes.

Calls


Stack ?? (-N arguments, 0 or +1 returns)

Stack 0

Stack +1

Stack 0 or +1

Stack -1

Object Manipulation


Stack -1

Stack -2

TODO: Push value first, then key?

Stack -3

TODO: Push value first, then key?

Stack ?? (-1 or 0 if return)

Stack ??

Stack -1 then +1 (effectively 0)

Stack 0

Stack +1

Raw Object Handling


Stack 0

Stack +1