mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add proper lua api deprecated handling
This commit is contained in:
parent
c03d7dc8a7
commit
b5acec0a3c
11 changed files with 75 additions and 3 deletions
|
@ -19,6 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "common/c_internal.h"
|
||||
#include "debug.h"
|
||||
#include "log.h"
|
||||
#include "main.h"
|
||||
#include "settings.h"
|
||||
|
||||
std::string script_get_backtrace(lua_State *L)
|
||||
{
|
||||
|
@ -109,4 +112,40 @@ void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode)
|
|||
lua_remove(L, -2); // Remove error handler
|
||||
}
|
||||
|
||||
void log_deprecated(lua_State *L, std::string message)
|
||||
{
|
||||
static bool configured = false;
|
||||
static bool dolog = false;
|
||||
static bool doerror = false;
|
||||
|
||||
// performance optimization to not have to read and compare setting for every logline
|
||||
if (!configured) {
|
||||
std::string value = g_settings->get("deprecated_lua_api_handling");
|
||||
if (value == "log") {
|
||||
dolog = true;
|
||||
}
|
||||
if (value == "error") {
|
||||
dolog = true;
|
||||
doerror = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doerror) {
|
||||
if (L != NULL) {
|
||||
script_error(L);
|
||||
} else {
|
||||
/* As of april 2014 assert is not optimized to nop in release builds
|
||||
* therefore this is correct. */
|
||||
assert("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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ std::string script_get_backtrace(lua_State *L);
|
|||
int script_error_handler(lua_State *L);
|
||||
int script_exception_wrapper(lua_State *L, lua_CFunction f);
|
||||
void script_error(lua_State *L);
|
||||
void script_run_callbacks(lua_State *L, int nargs,
|
||||
RunCallbacksMode mode);
|
||||
void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode);
|
||||
void log_deprecated(lua_State *L, std::string message);
|
||||
|
||||
#endif /* C_INTERNAL_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue