Created
February 9, 2019 01:00
-
-
Save sofar/3c1802e9dc1dba7c8fee5285e4608b13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/log.cpp b/src/log.cpp | |
index c84a847a..b784934d 100644 | |
--- a/src/log.cpp | |
+++ b/src/log.cpp | |
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., | |
#include "exceptions.h" | |
#include "util/numeric.h" | |
#include "log.h" | |
+#include "environment.h" | |
+#include "server.h" | |
#include <sstream> | |
#include <iostream> | |
@@ -278,7 +280,9 @@ void Logger::log(LogLevel lev, const std::string &text) | |
std::ostringstream os(std::ios_base::binary); | |
os << timestamp << ": " << label << "[" << thread_name << "]: " << text; | |
- logToOutputs(lev, os.str(), timestamp, thread_name, text); | |
+ // call lua log callbacks --FIXME !scope | |
+ if (!m_server->getScriptIface()->on_log_message(label, text)) | |
+ logToOutputs(lev, os.str(), timestamp, thread_name, text); | |
} | |
void Logger::logRaw(LogLevel lev, const std::string &text) | |
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp | |
index 3b461a2a..04590e0a 100644 | |
--- a/src/script/cpp_api/s_server.cpp | |
+++ b/src/script/cpp_api/s_server.cpp | |
@@ -146,6 +146,20 @@ bool ScriptApiServer::on_chat_message(const std::string &name, | |
return readParam<bool>(L, -1); | |
} | |
+bool ScriptApiServer::on_log_message(const std::string &level, | |
+ const std::string &message) | |
+{ | |
+ SCRIPTAPI_PRECHECKHEADER | |
+ // Get core.registered_on_log_messages | |
+ lua_getglobal(L, "core"); | |
+ lua_getfield(L, -1, "registered_on_log_messages"); | |
+ // Call callbacks | |
+ lua_pushstring(L, level.c_str()); | |
+ lua_pushstring(L, message.c_str()); | |
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC); | |
+ return readParam<bool>(L, -1); | |
+} | |
+ | |
void ScriptApiServer::on_mods_loaded() | |
{ | |
SCRIPTAPI_PRECHECKHEADER | |
diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h | |
index 769939d3..119a3e44 100644 | |
--- a/src/script/cpp_api/s_server.h | |
+++ b/src/script/cpp_api/s_server.h | |
@@ -30,6 +30,9 @@ class ScriptApiServer | |
// Returns true if script handled message | |
bool on_chat_message(const std::string &name, const std::string &message); | |
+ // Calls on_log_message handlers | |
+ bool on_log_message(const std::string &level, const std::string &message); | |
+ | |
// Calls when mods are loaded | |
void on_mods_loaded(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment