]> git.lizzy.rs Git - minetest.git/blobdiff - src/script/cpp_api/s_server.cpp
Overall improvements to log messages (#9598)
[minetest.git] / src / script / cpp_api / s_server.cpp
index 3b461a2a3b66a9214c55aa66a52ca752e5c0c441..1ce2f9d45d029fa8082364d966ba5544934971f6 100644 (file)
@@ -168,3 +168,25 @@ void ScriptApiServer::on_shutdown()
        runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
 }
 
+std::string ScriptApiServer::formatChatMessage(const std::string &name,
+       const std::string &message)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Push function onto stack
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "format_chat_message");
+
+       // Push arguments onto stack
+       lua_pushstring(L, name.c_str());
+       lua_pushstring(L, message.c_str());
+
+       // Actually call the function
+       lua_call(L, 2, 1);
+
+       // Fetch return value
+       std::string ret = lua_tostring(L, -1);
+       lua_pop(L, 1);
+
+       return ret;
+}