Scripting: Enhance error reporting

This commit is contained in:
Vicki Pfau 2023-09-16 01:30:40 -07:00
parent efb30080e8
commit beda1d5b87
2 changed files with 27 additions and 1 deletions

View File

@ -115,7 +115,6 @@ bool ScriptingController::load(VFileDevice& vf, const QString& name) {
}
bool ok = true;
if (!m_activeEngine->load(m_activeEngine, utf8.constData(), vf) || !m_activeEngine->run(m_activeEngine)) {
emit error(QString::fromUtf8(m_activeEngine->getError(m_activeEngine)));
ok = false;
}
if (m_controller) {

View File

@ -902,6 +902,30 @@ static const char* _reader(lua_State* lua, void* context, size_t* size) {
return reader->block;
}
void _luaError(struct mScriptEngineContextLua* luaContext) {
struct mScriptValue* console = mScriptContextGetGlobal(luaContext->d.context, "console");
struct mScriptValue error = {0};
bool ok = false;
if (console) {
ok = mScriptObjectGet(console, "error", &error);
}
if (ok) {
struct mScriptFrame frame;
mScriptFrameInit(&frame);
struct mScriptValue* this = mScriptListAppend(&frame.arguments);
this->type = console->type;
this->refs = mSCRIPT_VALUE_UNREF;
this->flags = 0;
this->value.opaque = console->value.opaque;
mSCRIPT_PUSH(&frame.arguments, CHARP, luaContext->lastError);
ok = mScriptInvoke(&error, &frame);
mScriptFrameDeinit(&frame);
}
if (!ok) {
mLOG(SCRIPT, ERROR, "%s", luaContext->lastError);
}
}
bool _luaLoad(struct mScriptEngineContext* ctx, const char* filename, struct VFile* vf) {
struct mScriptEngineContextLua* luaContext = (struct mScriptEngineContextLua*) ctx;
struct mScriptEngineLuaReader data = {
@ -988,6 +1012,7 @@ bool _luaLoad(struct mScriptEngineContext* ctx, const char* filename, struct VFi
case LUA_ERRSYNTAX:
luaContext->lastError = strdup(lua_tostring(luaContext->lua, -1));
lua_pop(luaContext->lua, 1);
_luaError(luaContext);
break;
default:
break;
@ -1118,6 +1143,8 @@ bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame*
if (ret == LUA_ERRRUN) {
luaContext->lastError = strdup(lua_tostring(luaContext->lua, -1));
lua_pop(luaContext->lua, 1);
_luaError(luaContext);
}
mScriptContextDeactivate(luaContext->d.context);
if (ret) {