summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-08-10 01:38:09 -0400
committerkwolekr <kwolekr@minetest.net>2015-08-10 01:38:09 -0400
commit18cfd89a86af550b3c4663def77a5fac46e895ae (patch)
treeb21ade5d67ac05682314317921a6431c5562035f
parenta953ff4dfc9f786ee379643b6b498a5699203ff1 (diff)
downloadminetest-18cfd89a86af550b3c4663def77a5fac46e895ae.tar.gz
minetest-18cfd89a86af550b3c4663def77a5fac46e895ae.tar.bz2
minetest-18cfd89a86af550b3c4663def77a5fac46e895ae.zip
Display Lua memory usage at the time of Out-of-Memory error
Also misc. minor cleanups
-rw-r--r--src/script/common/c_internal.cpp12
-rw-r--r--src/script/cpp_api/s_async.cpp2
2 files changed, 10 insertions, 4 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index bebf6ee69..0df0a7270 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -113,6 +113,11 @@ void script_error(lua_State *L, int pcall_result, const char *fxn)
}
err_msg += err_descr;
+ if (pcall_result == LUA_ERRMEM) {
+ err_msg += "\nCurrent Lua memory usage: "
+ + itos(lua_gc(L, LUA_GCCOUNT, 0) >> 10) + " MB";
+ }
+
throw LuaError(err_msg);
}
@@ -145,7 +150,9 @@ void script_run_callbacks_f(lua_State *L, int nargs,
// Stack now looks like this:
// ... <error handler> <run_callbacks> <table> <mode> <arg#1> <arg#2> ... <arg#n>
- script_error(L, lua_pcall(L, nargs + 2, 1, errorhandler), fxn);
+ int result = lua_pcall(L, nargs + 2, 1, errorhandler);
+ if (result != 0)
+ script_error(L, result, fxn);
lua_remove(L, -2); // Remove error handler
}
@@ -161,8 +168,7 @@ void log_deprecated(lua_State *L, const std::string &message)
std::string value = g_settings->get("deprecated_lua_api_handling");
if (value == "log") {
dolog = true;
- }
- if (value == "error") {
+ } else if (value == "error") {
dolog = true;
doerror = true;
}
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp
index 0e2a006ca..c00b22f98 100644
--- a/src/script/cpp_api/s_async.cpp
+++ b/src/script/cpp_api/s_async.cpp
@@ -255,7 +255,7 @@ void* AsyncWorkerThread::Thread()
std::string script = getServer()->getBuiltinLuaPath() + DIR_DELIM + "init.lua";
if (!loadScript(script)) {
errorstream
- << "AsyncWorkderThread execution of async base environment failed!"
+ << "AsyncWorkerThread execution of async base environment failed!"
<< std::endl;
abort();
}