Skip to content

Commit

Permalink
Display Lua memory usage at the time of Out-of-Memory error
Browse files Browse the repository at this point in the history
Also misc. minor cleanups
  • Loading branch information
kwolekr committed Aug 10, 2015
1 parent a953ff4 commit 18cfd89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/script/common/c_internal.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/script/cpp_api/s_async.cpp
Expand Up @@ -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();
}
Expand Down

0 comments on commit 18cfd89

Please sign in to comment.