Skip to content

Commit 18cfd89

Browse files
committedAug 10, 2015
Display Lua memory usage at the time of Out-of-Memory error
Also misc. minor cleanups
1 parent a953ff4 commit 18cfd89

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

Diff for: ‎src/script/common/c_internal.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void script_error(lua_State *L, int pcall_result, const char *fxn)
113113
}
114114
err_msg += err_descr;
115115

116+
if (pcall_result == LUA_ERRMEM) {
117+
err_msg += "\nCurrent Lua memory usage: "
118+
+ itos(lua_gc(L, LUA_GCCOUNT, 0) >> 10) + " MB";
119+
}
120+
116121
throw LuaError(err_msg);
117122
}
118123

@@ -145,7 +150,9 @@ void script_run_callbacks_f(lua_State *L, int nargs,
145150
// Stack now looks like this:
146151
// ... <error handler> <run_callbacks> <table> <mode> <arg#1> <arg#2> ... <arg#n>
147152

148-
script_error(L, lua_pcall(L, nargs + 2, 1, errorhandler), fxn);
153+
int result = lua_pcall(L, nargs + 2, 1, errorhandler);
154+
if (result != 0)
155+
script_error(L, result, fxn);
149156

150157
lua_remove(L, -2); // Remove error handler
151158
}
@@ -161,8 +168,7 @@ void log_deprecated(lua_State *L, const std::string &message)
161168
std::string value = g_settings->get("deprecated_lua_api_handling");
162169
if (value == "log") {
163170
dolog = true;
164-
}
165-
if (value == "error") {
171+
} else if (value == "error") {
166172
dolog = true;
167173
doerror = true;
168174
}

Diff for: ‎src/script/cpp_api/s_async.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void* AsyncWorkerThread::Thread()
255255
std::string script = getServer()->getBuiltinLuaPath() + DIR_DELIM + "init.lua";
256256
if (!loadScript(script)) {
257257
errorstream
258-
<< "AsyncWorkderThread execution of async base environment failed!"
258+
<< "AsyncWorkerThread execution of async base environment failed!"
259259
<< std::endl;
260260
abort();
261261
}

0 commit comments

Comments
 (0)
Please sign in to comment.