diff options
author | Maya <malte.hoermeyer@web.de> | 2022-11-13 04:01:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-13 03:01:14 +0000 |
commit | 23fda0b842560d2f3cf64ecf9a57d5ad2861e488 (patch) | |
tree | 9527c91bd744fb0562963e43e212c1bc5536847d /NorthstarDLL/scriptjson.cpp | |
parent | d237401bb97c1fa2d6ee87220d49e4b3343e7201 (diff) | |
download | NorthstarLauncher-23fda0b842560d2f3cf64ecf9a57d5ad2861e488.tar.gz NorthstarLauncher-23fda0b842560d2f3cf64ecf9a57d5ad2861e488.zip |
Squirrel functions auto bind (#299)
* Add defines to auto add squirrel funcs
it brokey
* Make it Work
changed all squirrel function definitions to this system
* Add defines to auto add squirrel funcs
it brokey
Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com>
* Make it Work
changed all squirrel function definitions to this system
Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com>
* Formatting
* Good old Formatting commit
* HelloGecko
* Formatting Finalv2ForRealThisTime
* idk anymore
* i hate formatting
* Rename some
* Rename macro
* Change function names to more human-readable
* Revert to using old ScriptContext definition
* Formatting
Co-authored-by: RoyalBlue1 <realEmail@veryRealURL.com>
Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com>
Co-authored-by: Emma Miler <emma.pi@protonmail.com>
Co-authored-by: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Diffstat (limited to 'NorthstarDLL/scriptjson.cpp')
-rw-r--r-- | NorthstarDLL/scriptjson.cpp | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/NorthstarDLL/scriptjson.cpp b/NorthstarDLL/scriptjson.cpp index a9767615..8efad7b4 100644 --- a/NorthstarDLL/scriptjson.cpp +++ b/NorthstarDLL/scriptjson.cpp @@ -208,8 +208,12 @@ template <ScriptContext context> void EncodeJSONArray( } } -// table function DecodeJSON( string json, bool fatalParseErrors = false ) -template <ScriptContext context> SQRESULT SQ_DecodeJSON(HSquirrelVM* sqvm) +ADD_SQFUNC( + "table", + DecodeJSON, + "string json, bool fatalParseErrors = false", + "converts a json string to a squirrel table", + ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER) { const char* pJson = g_pSquirrel<context>->getstring(sqvm, 1); const bool bFatalParseErrors = g_pSquirrel<context>->getbool(sqvm, 2); @@ -236,8 +240,12 @@ template <ScriptContext context> SQRESULT SQ_DecodeJSON(HSquirrelVM* sqvm) DecodeJsonTable<context>(sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&doc); } -// string function EncodeJSON( table data ) -template <ScriptContext context> SQRESULT SQ_EncodeJSON(HSquirrelVM* sqvm) +ADD_SQFUNC( + "string", + EncodeJSON, + "table data", + "converts a squirrel table to a json string", + ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER) { rapidjson_document doc; doc.SetObject(); @@ -255,28 +263,3 @@ template <ScriptContext context> SQRESULT SQ_EncodeJSON(HSquirrelVM* sqvm) g_pSquirrel<context>->pushstring(sqvm, pJsonString, -1); return SQRESULT_NOTNULL; } - -ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientScriptJSON, ClientSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( - "table", - "DecodeJSON", - "string json, bool fatalParseErrors = false", - "converts a json string to a squirrel table", - SQ_DecodeJSON<ScriptContext::CLIENT>); - g_pSquirrel<ScriptContext::CLIENT>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::CLIENT>); - - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "table", "DecodeJSON", "string json", "converts a json string to a squirrel table", SQ_DecodeJSON<ScriptContext::UI>); - g_pSquirrel<ScriptContext::UI>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::UI>); -} - -ON_DLL_LOAD_RELIESON("server.dll", ServerScriptJSON, ServerSquirrel, (CModule module)) -{ - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "table", "DecodeJSON", "string json", "converts a json string to a squirrel table", SQ_DecodeJSON<ScriptContext::SERVER>); - g_pSquirrel<ScriptContext::SERVER>->AddFuncRegistration( - "string", "EncodeJSON", "table data", "converts a squirrel table to a json string", SQ_EncodeJSON<ScriptContext::SERVER>); -} |