Skip to content

Commit a22951a

Browse files
committed
chore(plugins/lua): Custom Panic
1 parent 81b5fb7 commit a22951a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/plugins/lua/LuaPlugin.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ static const luaL_Reg lualibs[] = {
3232

3333
void SetupLuaEnvironment(LuaPlugin *plugin, lua_State *state);
3434

35+
static int LuaPanicFunction(lua_State *state)
36+
{
37+
std::string m_what = "Missing Error";
38+
if (lua_gettop(state) > 0)
39+
{
40+
char const *s = lua_tostring(state, -1);
41+
m_what = s ? s : "";
42+
}
43+
44+
PLUGIN_PRINT("Runtime", "A Lua runtime panic has been triggered.\n");
45+
PLUGIN_PRINTF("Runtime", "Plugin: %s\n", luabridge::getGlobal(state, "plugin_name").tostring().c_str());
46+
PLUGIN_PRINTF("Runtime", "Error: %s\n", m_what.c_str());
47+
return 0;
48+
}
49+
3550
bool LuaPlugin::LoadScriptingEnvironment()
3651
{
3752
this->SetLoadError("");
@@ -107,6 +122,8 @@ bool LuaPlugin::LoadScriptingEnvironment()
107122
}
108123
}
109124

125+
lua_atpanic(this->state, LuaPanicFunction);
126+
110127
return true;
111128
}
112129

0 commit comments

Comments
 (0)