summaryrefslogtreecommitdiff
path: root/src/script/common/c_internal.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-04-29 17:47:34 +0200
committersapier <Sapier at GMX dot net>2014-04-29 22:49:04 +0200
commitb5acec0a3c5701c53854ff7afdf4008863e6e8df (patch)
tree19ed8671c3b56e82e803c51eaad92948b806d13a /src/script/common/c_internal.cpp
parentc03d7dc8a7c35708a39f9c14e2df243e212b283b (diff)
downloadminetest-b5acec0a3c5701c53854ff7afdf4008863e6e8df.tar.gz
minetest-b5acec0a3c5701c53854ff7afdf4008863e6e8df.tar.bz2
minetest-b5acec0a3c5701c53854ff7afdf4008863e6e8df.zip
Add proper lua api deprecated handling
Diffstat (limited to 'src/script/common/c_internal.cpp')
-rw-r--r--src/script/common/c_internal.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index 4263dec90..4c6604f65 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -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;
+ }
+ }
+}