mirror of https://github.com/mgba-emu/mgba.git
Scripting: Enhance error reporting
This commit is contained in:
parent
404e84b045
commit
d2205d3475
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue