diff options
author | Tom Barham <me@cpdt.dev> | 2022-02-22 08:33:53 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 19:33:53 -0300 |
commit | 8c9f34283f8670dda98959d0785d682e6f652a93 (patch) | |
tree | 5e9d8c10fb5d1df2816fac43e4db3b80cc7f93a0 /NorthstarDedicatedTest/squirrel.h | |
parent | ae9df9bc734c6c0364028c71db5e7236e7c344dd (diff) | |
download | NorthstarLauncher-8c9f34283f8670dda98959d0785d682e6f652a93.tar.gz NorthstarLauncher-8c9f34283f8670dda98959d0785d682e6f652a93.zip |
Advanced chat: custom messages and client hooks (#74)
Co-authored-by: Emma Miler <27428383+emma-miler@users.noreply.github.com>
Diffstat (limited to 'NorthstarDedicatedTest/squirrel.h')
-rw-r--r-- | NorthstarDedicatedTest/squirrel.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index 8e851266..b01618f2 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -124,6 +124,10 @@ typedef SQBool (*sq_getboolType)(void*, SQInteger stackpos); extern sq_getboolType ClientSq_getbool; extern sq_getboolType ServerSq_getbool; +typedef SQRESULT (*sq_getType)(void* sqvm, SQInteger idx); +extern sq_getType ServerSq_sq_get; +extern sq_getType ClientSq_sq_get; + template <ScriptContext context> class SquirrelManager { private: @@ -193,6 +197,66 @@ template <ScriptContext context> class SquirrelManager } } + int setupfunc(const char* funcname) + { + int result = -2; + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + { + ClientSq_pushroottable(sqvm2); + ClientSq_pushstring(sqvm2, funcname, -1); + result = ClientSq_sq_get(sqvm2, -2); + ClientSq_pushroottable(sqvm2); + } + else if (context == ScriptContext::SERVER) + { + ServerSq_pushroottable(sqvm2); + ServerSq_pushstring(sqvm2, funcname, -1); + result = ServerSq_sq_get(sqvm2, -2); + ServerSq_pushroottable(sqvm2); + } + return result; + } + + void pusharg(int arg) + { + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + ClientSq_pushinteger(sqvm2, arg); + else if (context == ScriptContext::SERVER) + ServerSq_pushinteger(sqvm2, arg); + } + void pusharg(const char* arg) + { + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + ClientSq_pushstring(sqvm2, arg, -1); + else if (context == ScriptContext::SERVER) + ServerSq_pushstring(sqvm2, arg, -1); + } + void pusharg(float arg) + { + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + ClientSq_pushfloat(sqvm2, arg); + else if (context == ScriptContext::SERVER) + ServerSq_pushfloat(sqvm2, arg); + } + void pusharg(bool arg) + { + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + ClientSq_pushbool(sqvm2, arg); + else if (context == ScriptContext::SERVER) + ServerSq_pushbool(sqvm2, arg); + } + + int call(int args) + { + int result = -2; + if (context == ScriptContext::CLIENT || context == ScriptContext::UI) + result = ClientSq_call(sqvm2, args + 1, false, false); + else if (context == ScriptContext::SERVER) + result = ServerSq_call(sqvm2, args + 1, false, false); + + return result; + } + void AddFuncRegistration(std::string returnType, std::string name, std::string argTypes, std::string helpText, SQFunction func) { SQFuncRegistration* reg = new SQFuncRegistration; |