Warning
Parameters or descriptions may be wrong or incomplete
This list is incomplete and only lists methods available in squirrel.h.
Some descriptions are taken from the Squirrel Documentation
Object creation and handling¶
SquirrelManager
You can access all sq functions only with a SquirrelManager instance. You have one available inside the ADD_SQFUNC macro.
Pushing Objects to the stack¶
void pushbool(HSquirrelVM* sqvm, const SQBool bVal)
HSquirrelVM* sqvmthe target VMSQInteger bValthe bool that will be pushed
pushes a boolean to the stack
void pushinteger(HSquirrelVM* sqvm, const SQInteger iVal)
HSquirrelVM* sqvmthe target VMSQInteger iValthe integer that will be pushed
void pushfloat(HSquirrelVM* sqvm, const SQFloat fVal)
HSquirrelVM* sqvmthe target VMSQInteger fValthe float that will be pushed
pushes a float to the stack
void pushstring(HSquirrelVM* sqvm, const SQChar* sVal, int length = -1)
HSquirrelVM* sqvmthe target VMSQChar* sValthe string that will be pushedint lenlength of the stringsVal. If the parameter length is less than 0 the VM will calculate the length usingstrlen
pushes a string to the stack
void pushasset(HSquirrelVM* sqvm, const SQChar* sVal, int length = -1)
HSquirrelVM* sqvmthe target VMSQChar* sValthe string that will be pushedint lenlength of the stringsVal. If the parameter length is less than 0 the VM will calculate the length usingstrlen
pushes an asset to the stack
void pushvector(HSquirrelVM* sqvm, const Vector3 vVal)
HSquirrelVM* sqvmthe target VMVector3 vValthe vector that will be pushed
pushes a vector to the stack
void pushobject(HSquirrelVM* sqvm, SQObject obj)
HSquirrelVM* sqvmthe target VMSQObject objthe object that will be pushed
pushes an object like functions to the stack
void pushroottable(HSquirrelVM* sqvm)
HSquirrelVM* sqvmthe target VM
pushes the current root table into the stack
Note
sq_pushnull (0x33D0) and more aren't included in squirrel.h right now but may be in the future.
Getting Objects from the stack¶
SQBool getbool(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
SQInteger getinteger(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
SQFloat getfloat(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
SQChar* getstring(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
Vector3 getvector(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
SQChar* getasset(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object- Returns The value of the object
SQTable* getConstants(HSquirrelVM* sqvm)
Note
This function (`server.dll+0x5920```) is not available in the launcher or plugins at the moment.
You can open a PR if you need it now.
To define an integer constant you can use defconst instead.
HSquirrelVM* sqvmthe target vm- Returns the table of constants
Pushes the constants table to the stack.
Used to add global constants for scripts.
getConstants(sqvm);
pushstring(sqvm, "MY_CONSTANT");
pushstring(sqvm, "MY_VALUE");
newslot(sqvm, -3, false);
removeFromStack(sqvm); // don't forget this!
int sq_getfunction(HSquirrelVM* sqvm, const SQChar* name, SQObject* returnObj, const SQChar* signature)
HSquirrelVM* sqvmthe target vmSQChar* namethe function name to search forSQObject* returnObjreference to the object to hold the function objectSQChar* signature
returns 0 if the function was found.
SQObject functionobj {};
int result = sq_getfunction(m_pSQVM->sqvm, funcname, &functionobj, 0);
if (result != 0) // This func returns 0 on success for some reason
{
NS::log::squirrel_logger<context>()->error("Call was unable to find function with name '{}'. Is it global?", funcname);
return SQRESULT_ERROR;
}
T* getentity(HSquirrelVM* sqvm, SQInteger iStackPos)
HSquirrelVM* sqvmThe target vmSQInteger iStackPosStack position of the entity
void* __sq_getentityfrominstance(CSquirrelVM* sqvm, SQObject* pInstance, char** ppEntityConstant)
CSquirrelVM* sqvmThe target vmSQObject* pInstanceInstance holding an entitychar** ppEntityConstantEntity constant likeref__sq_GetEntityConstant_CBaseEntity`
char** __sq_GetEntityConstant_CBaseEntity()
There are entity constants for other types, but seemingly CBaseEntity's is the only one needed
SQRESULT __sq_getobject(HSquirrelVM* sqvm, SQInteger iStackPos, SQObject* obj)
HSquirrelVM* sqvmThe target vmSQInteger iStackPosStack position of the objectSQObject* objPointer that will hold the object
obj will be overwritten to hold the squirrel object.
This example adds a native function with the ADD_SQFUNC macro.
The function takes a function reference as a callback and calls it immediately.
More information about function calls are available here
ADD_SQFUNC("void", SQCallbackTest, "void functionref()", "", ScriptContext::UI)
{
SQObject fn; // Make an empty sqobject. This will hold the function object later
g_pSquirrel<context>->__sq_getobject(sqvm, 1, &fn); // Assign the function object to the SQOBJECT
g_pSquirrel<context>->pushobject(sqvm, &fn); // Push the function object for the call
g_pSquirrel<context>->pushroottable(sqvm); // Push the root table for the function stack
g_pSquirrel<context>->__sq_call(sqvm, 1, false, true); // call the function with one parameter (the 'this' object)
return SQRESULT_NULL;
}
SQRESULT get(HSquirrelVM* sqvm, const SQInteger stackpos)
HSquirrelVM* sqvmthe target vmSQInteger stackposstack position of the object
Returns an SQRESULT that indicates whether or not the access was successful.
pops a key from the stack and performs a get operation on the object at the position idx in the stack; and pushes the result in the stack.
Stack Infos¶
SQRESULT sq_stackinfos(HSquirrelVM* sqvm, int level, SQStackInfos& out)
HSquirrelVM* sqvmthe target vmint levelstack depth of the infoSQStackInfos& outinstance that will hold the information
Mod* getcallingmod(HSquirrelVM* sqvm, int depth = 0)
HSquirrelVM* sqvmthe target vmint depthstack depth of the origin mod- Returns Pointer to the Mod object at the stack depth
Note
Not available in plugins
Other¶
void defconst(CSquirrelVM* csqvm, const SQChar* pName, int nValue)
CSquirrelVM* csqvmthe target vmSQChar* pNamethe constant nameint nValuethe constant value
defines a global squirrel integer constant