diff options
Diffstat (limited to 'NorthstarDLL/squirrel')
-rw-r--r-- | NorthstarDLL/squirrel/squirrel.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/NorthstarDLL/squirrel/squirrel.cpp b/NorthstarDLL/squirrel/squirrel.cpp index d594ede9..58f79e00 100644 --- a/NorthstarDLL/squirrel/squirrel.cpp +++ b/NorthstarDLL/squirrel/squirrel.cpp @@ -527,38 +527,37 @@ template <ScriptContext context> void StubUnsafeSQFuncs() template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBuffer() { - auto maybeMessage = messageBuffer->pop(); - if (!maybeMessage) + while (std::optional<SquirrelMessage> maybeMessage = messageBuffer->pop()) { - return; - } + SquirrelMessage message = maybeMessage.value(); - SquirrelMessage message = maybeMessage.value(); + SQObject functionobj {}; + 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 + { + NS::log::squirrel_logger<context>()->error( + "ProcessMessageBuffer was unable to find function with name '{}'. Is it global?", message.functionName); + continue; + } - SQObject functionobj {}; - 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 - { - NS::log::squirrel_logger<context>()->error( - "ProcessMessageBuffer was unable to find function with name '{}'. Is it global?", message.functionName); - return; - } - pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object - pushroottable(m_pSQVM->sqvm); - if (message.isExternal) - { - message.externalFunc(m_pSQVM->sqvm); - } - else - { - for (auto& v : message.args) + pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object + pushroottable(m_pSQVM->sqvm); + + if (message.isExternal) { - // Execute lambda to push arg to stack - v(); + message.externalFunc(m_pSQVM->sqvm); + } + else + { + for (auto& v : message.args) + { + // Execute lambda to push arg to stack + v(); + } } - } - _call(m_pSQVM->sqvm, message.args.size()); + _call(m_pSQVM->sqvm, message.args.size()); + } } ADD_SQFUNC( |