mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
add lua logging facilities as Util.Log*() functions
This commit is contained in:
parent
e2d7721438
commit
1237e7e533
@ -214,6 +214,10 @@ void RegisterThread(const std::string& str);
|
|||||||
do { \
|
do { \
|
||||||
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
Application::Console().Write(_this_location + std::string("[LUA ERROR] ") + (x)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
#define beammp_lua_log(level, plugin, x) \
|
||||||
|
do { \
|
||||||
|
Application::Console().Write(_this_location + fmt::format("[{}] [{}] ", plugin, level) + (x)); \
|
||||||
|
} while (false)
|
||||||
#define beammp_lua_warn(x) \
|
#define beammp_lua_warn(x) \
|
||||||
do { \
|
do { \
|
||||||
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
|
Application::Console().Write(_this_location + std::string("[LUA WARN] ") + (x)); \
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "TLuaEngine.h"
|
#include "TLuaEngine.h"
|
||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
|
#include "Common.h"
|
||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
#include "LuaAPI.h"
|
#include "LuaAPI.h"
|
||||||
@ -829,6 +830,30 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
|
|||||||
MPTable.set_function("Set", &LuaAPI::MP::Set);
|
MPTable.set_function("Set", &LuaAPI::MP::Set);
|
||||||
|
|
||||||
auto UtilTable = StateView.create_named_table("Util");
|
auto UtilTable = StateView.create_named_table("Util");
|
||||||
|
UtilTable.set_function("LogInfo", [this](sol::variadic_args args) {
|
||||||
|
std::string ToPrint = "";
|
||||||
|
for (const auto& arg : args) {
|
||||||
|
ToPrint += LuaAPI::LuaToString(static_cast<const sol::object>(arg));
|
||||||
|
ToPrint += "\t";
|
||||||
|
}
|
||||||
|
beammp_lua_log("INFO", mStateId, ToPrint);
|
||||||
|
});
|
||||||
|
UtilTable.set_function("LogWarn", [this](sol::variadic_args args) {
|
||||||
|
std::string ToPrint = "";
|
||||||
|
for (const auto& arg : args) {
|
||||||
|
ToPrint += LuaAPI::LuaToString(static_cast<const sol::object>(arg));
|
||||||
|
ToPrint += "\t";
|
||||||
|
}
|
||||||
|
beammp_lua_log("WARN", mStateId, ToPrint);
|
||||||
|
});
|
||||||
|
UtilTable.set_function("LogError", [this](sol::variadic_args args) {
|
||||||
|
std::string ToPrint = "";
|
||||||
|
for (const auto& arg : args) {
|
||||||
|
ToPrint += LuaAPI::LuaToString(static_cast<const sol::object>(arg));
|
||||||
|
ToPrint += "\t";
|
||||||
|
}
|
||||||
|
beammp_lua_log("ERROR", mStateId, ToPrint);
|
||||||
|
});
|
||||||
UtilTable.set_function("JsonEncode", &LuaAPI::MP::JsonEncode);
|
UtilTable.set_function("JsonEncode", &LuaAPI::MP::JsonEncode);
|
||||||
UtilTable.set_function("JsonDecode", [this](const std::string& str) {
|
UtilTable.set_function("JsonDecode", [this](const std::string& str) {
|
||||||
return Lua_JsonDecode(str);
|
return Lua_JsonDecode(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user