diff options
author | ANAND <ClobberXD@gmail.com> | 2019-08-08 21:34:46 +0530 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2019-08-08 17:04:46 +0100 |
commit | d1c27c7e8037e9f438741ee5f7d3b6bda22d22a0 (patch) | |
tree | fa04794d876ec4c912add9fcca36eff4a18df016 /src/script/cpp_api/s_server.cpp | |
parent | cc610c74a742511e04dce91b24d09c860ca7fa1b (diff) | |
download | hax-minetest-server-d1c27c7e8037e9f438741ee5f7d3b6bda22d22a0.tar.gz hax-minetest-server-d1c27c7e8037e9f438741ee5f7d3b6bda22d22a0.zip |
Allow customizing chat message format (#8529)
Diffstat (limited to '')
-rw-r--r-- | src/script/cpp_api/s_server.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp index 3b461a2a3..1ce2f9d45 100644 --- a/src/script/cpp_api/s_server.cpp +++ b/src/script/cpp_api/s_server.cpp @@ -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; +} |