aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/squirrelautobind.h
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2022-12-19 19:32:16 +0100
committerGitHub <noreply@github.com>2022-12-19 19:32:16 +0100
commite04f3b36accccb590a2d51b4829256b9964ac3fd (patch)
tree20ee30c82e6f53e6e772be2e1b9613eebca12bf3 /NorthstarDLL/squirrelautobind.h
parent33f18a735986dcd136bf8ba70ad8331306c28227 (diff)
downloadNorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.tar.gz
NorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.zip
Restructuring (#365)
* Remove launcher proxy * Restructuring * More restructuring * Fix include dirs * Fix merge * Remove clang thing * Filters * Oops
Diffstat (limited to 'NorthstarDLL/squirrelautobind.h')
-rw-r--r--NorthstarDLL/squirrelautobind.h76
1 files changed, 0 insertions, 76 deletions
diff --git a/NorthstarDLL/squirrelautobind.h b/NorthstarDLL/squirrelautobind.h
deleted file mode 100644
index 865479a1..00000000
--- a/NorthstarDLL/squirrelautobind.h
+++ /dev/null
@@ -1,76 +0,0 @@
-#pragma once
-#include <vector>
-
-typedef void (*SqAutoBindFunc)();
-
-class SquirrelAutoBindContainer
-{
- public:
- std::vector<std::function<void()>> clientSqAutoBindFuncs;
- std::vector<std::function<void()>> serverSqAutoBindFuncs;
-};
-
-extern SquirrelAutoBindContainer* g_pSqAutoBindContainer;
-
-class __squirrelautobind;
-
-#define ADD_SQFUNC(returnType, funcName, argTypes, helpText, runOnContext) \
- template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \
- namespace \
- { \
- __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \
- []() \
- { \
- if constexpr (runOnContext & ScriptContext::UI) \
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( \
- returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::UI >); \
- if constexpr (runOnContext & ScriptContext::CLIENT) \
- g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( \
- returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::CLIENT >); \
- }, \
- []() \
- { \
- if constexpr (runOnContext & ScriptContext::SERVER) \
- g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( \
- returnType, __STR(funcName), argTypes, helpText, CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \
- }); \
- } \
- template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm)
-
-#define REPLACE_SQFUNC(funcName, runOnContext) \
- template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm); \
- namespace \
- { \
- __squirrelautobind CONCAT2(__squirrelautobind, __LINE__)( \
- []() \
- { \
- if constexpr (runOnContext & ScriptContext::UI) \
- g_pSquirrel<ScriptContext::UI>->AddFuncOverride(__STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::UI >); \
- if constexpr (runOnContext & ScriptContext::CLIENT) \
- g_pSquirrel<ScriptContext::CLIENT>->AddFuncOverride( \
- __STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::CLIENT >); \
- }, \
- []() \
- { \
- if constexpr (runOnContext & ScriptContext::SERVER) \
- g_pSquirrel<ScriptContext::SERVER>->AddFuncOverride( \
- __STR(funcName), CONCAT2(Script_, funcName) < ScriptContext::SERVER >); \
- }); \
- } \
- template <ScriptContext context> SQRESULT CONCAT2(Script_, funcName)(HSquirrelVM * sqvm)
-
-class __squirrelautobind
-{
- public:
- __squirrelautobind() = delete;
-
- __squirrelautobind(std::function<void()> clientAutoBindFunc, std::function<void()> serverAutoBindFunc)
- {
- // Bit hacky but we can't initialise this normally since this gets run automatically on load
- if (g_pSqAutoBindContainer == nullptr)
- g_pSqAutoBindContainer = new SquirrelAutoBindContainer();
-
- g_pSqAutoBindContainer->clientSqAutoBindFuncs.push_back(clientAutoBindFunc);
- g_pSqAutoBindContainer->serverSqAutoBindFuncs.push_back(serverAutoBindFunc);
- }
-};