1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 16:45:20 +02:00

Use warningstream for deprecated field messages and refactor log_deprecated

This commit is contained in:
ShadowNinja
2015-10-15 01:08:18 -04:00
committed by kwolekr
parent 659922fd30
commit 7b8d372947
2 changed files with 30 additions and 40 deletions

View File

@@ -163,35 +163,26 @@ void script_run_callbacks_f(lua_State *L, int nargs,
void log_deprecated(lua_State *L, const std::string &message)
{
static bool configured = false;
static bool dolog = false;
static bool doerror = false;
static bool do_log = false;
static bool do_error = false;
// performance optimization to not have to read and compare setting for every logline
// Only read settings on first call
if (!configured) {
std::string value = g_settings->get("deprecated_lua_api_handling");
if (value == "log") {
dolog = true;
do_log = true;
} else if (value == "error") {
dolog = true;
doerror = true;
do_log = true;
do_error = true;
}
}
if (doerror) {
if (L != NULL) {
if (do_log) {
warningstream << message << std::endl;
if (do_error)
script_error(L, LUA_ERRRUN, NULL, NULL);
} else {
FATAL_ERROR("Can't do a scripterror for this deprecated message, "
"so exit completely!");
}
}
if (dolog) {
/* abusing actionstream because of lack of file-only-logged loglevel */
actionstream << message << std::endl;
if (L != NULL) {
actionstream << script_get_backtrace(L) << std::endl;
}
else
infostream << script_get_backtrace(L) << std::endl;
}
}