Fix CLI abort when non lua string passed to error (#114)

This commit is contained in:
Grant Hernandez 2021-11-03 21:17:07 -07:00 committed by GitHub
parent 733ae0498d
commit e3f8c25e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 2 deletions

View File

@ -169,7 +169,17 @@ static std::string runCode(lua_State* L, const std::string& source)
}
else
{
std::string error = (status == LUA_YIELD) ? "thread yielded unexpectedly" : lua_tostring(T, -1);
std::string error;
if (status == LUA_YIELD)
{
error = "thread yielded unexpectedly";
}
else if (const char* str = lua_tostring(L, -1))
{
error = str;
}
error += "\nstack backtrace:\n";
error += lua_debugtrace(T);
@ -322,7 +332,17 @@ static bool runFile(const char* name, lua_State* GL)
}
else
{
std::string error = (status == LUA_YIELD) ? "thread yielded unexpectedly" : lua_tostring(L, -1);
std::string error;
if (status == LUA_YIELD)
{
error = "thread yielded unexpectedly";
}
else if (const char* str = lua_tostring(L, -1))
{
error = str;
}
error += "\nstacktrace:\n";
error += lua_debugtrace(L);