diff --git a/src/platform/qt/scripting/ScriptingController.cpp b/src/platform/qt/scripting/ScriptingController.cpp index 8396a6a63..05fdac14c 100644 --- a/src/platform/qt/scripting/ScriptingController.cpp +++ b/src/platform/qt/scripting/ScriptingController.cpp @@ -80,7 +80,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) { diff --git a/src/script/engines/lua.c b/src/script/engines/lua.c index f2b8e2c4e..fea8c6961 100644 --- a/src/script/engines/lua.c +++ b/src/script/engines/lua.c @@ -810,6 +810,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 = { @@ -861,6 +885,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; @@ -967,6 +992,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); } if (ret) { return false;