From 08c30b23cdda07fe5564030f8c55b9becc460566 Mon Sep 17 00:00:00 2001 From: Emma Miler Date: Sun, 11 Dec 2022 22:57:18 +0100 Subject: Log function lookup failure on Call (#355) * Log function lookup failure on Call * Formatting * Update squirrel.cpp * format --- NorthstarDLL/dllmain.cpp | 1 + NorthstarDLL/logging.h | 1 - NorthstarDLL/loghooks.cpp | 1 + NorthstarDLL/squirrel.cpp | 6 ++---- NorthstarDLL/squirrel.h | 10 ++++++++++ 5 files changed, 14 insertions(+), 5 deletions(-) (limited to 'NorthstarDLL') diff --git a/NorthstarDLL/dllmain.cpp b/NorthstarDLL/dllmain.cpp index 44d973f2..4a9da4af 100644 --- a/NorthstarDLL/dllmain.cpp +++ b/NorthstarDLL/dllmain.cpp @@ -8,6 +8,7 @@ #include "plugins.h" #include "version.h" #include "pch.h" +#include "squirrel.h" #include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" diff --git a/NorthstarDLL/logging.h b/NorthstarDLL/logging.h index a75dce91..78f65e18 100644 --- a/NorthstarDLL/logging.h +++ b/NorthstarDLL/logging.h @@ -2,7 +2,6 @@ #include "pch.h" #include "spdlog/sinks/base_sink.h" #include "spdlog/logger.h" -#include "squirrel.h" #include "color.h" void CreateLogFiles(); diff --git a/NorthstarDLL/loghooks.cpp b/NorthstarDLL/loghooks.cpp index 316d34ae..a352f4c1 100644 --- a/NorthstarDLL/loghooks.cpp +++ b/NorthstarDLL/loghooks.cpp @@ -6,6 +6,7 @@ #include "bitbuf.h" #include "nsprefix.h" #include "tier0.h" +#include "squirrel.h" #include #include diff --git a/NorthstarDLL/squirrel.cpp b/NorthstarDLL/squirrel.cpp index a5733784..fb4e77c5 100644 --- a/NorthstarDLL/squirrel.cpp +++ b/NorthstarDLL/squirrel.cpp @@ -528,10 +528,8 @@ template void SquirrelManager::ProcessMessageBu int result = sq_getfunction(m_pSQVM->sqvm, message.functionName.c_str(), &functionobj, 0); if (result != 0) // This func returns 0 on success for some reason { - spdlog::error( - "ProcessMessageBuffer was unable to find function with name '{}' on {}. Is it global?", - message.functionName, - GetContextName(context)); + NS::log::squirrel_logger()->error( + "ProcessMessageBuffer was unable to find function with name '{}'. Is it global?", message.functionName); return; } pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object diff --git a/NorthstarDLL/squirrel.h b/NorthstarDLL/squirrel.h index 65dd66c5..a1f1dd5f 100644 --- a/NorthstarDLL/squirrel.h +++ b/NorthstarDLL/squirrel.h @@ -3,6 +3,7 @@ #include "squirrelclasstypes.h" #include "squirrelautobind.h" #include "vector.h" +#include "logging.h" // stolen from ttf2sdk: sqvm types typedef float SQFloat; @@ -36,6 +37,13 @@ const char* GetContextName_Short(ScriptContext context); eSQReturnType SQReturnTypeFromString(const char* pReturnType); const char* SQTypeNameFromID(const int iTypeId); +std::shared_ptr getSquirrelLoggerByContext(ScriptContext context); + +namespace NS::log +{ + template std::shared_ptr squirrel_logger(); +}; // namespace NS::log + void schedule_call_external(ScriptContext context, const char* func_name, SquirrelMessage_External_Pop function); // This base class means that only the templated functions have to be rebuilt for each template instance @@ -297,6 +305,7 @@ template class SquirrelManager : public virtual Squirrel 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()->error("Call was unable to find function with name '{}'. Is it global?", funcname); return SQRESULT_ERROR; } pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object @@ -319,6 +328,7 @@ template class SquirrelManager : public virtual Squirrel 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()->error("Call was unable to find function with name '{}'. Is it global?", funcname); return SQRESULT_ERROR; } pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object -- cgit v1.2.3