Fix certain Lua script errors hanging the GUI (#899)

* Fixed a bug where a standalone Lua script w/o a run function will hang the GUI on non-color radios

* Prevent Lua standalone window from opening if Lua failed on load

* Fixed scroll down key in TX12 simulator
Copied key definitions from TX16S

* Fixed the Lua error trying to call nil value when no scripts are loaded.

* I messed up in the previous commit; now it does not freeze and it does not call nil.
This commit is contained in:
Jesper Frickmann
2021-10-15 12:03:23 +11:00
committed by GitHub
parent b1a41438a3
commit ecf386e71f
4 changed files with 18 additions and 12 deletions
+11 -7
View File
@@ -891,6 +891,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
if (sid.run == LUA_NOREF) {
TRACE_ERROR("luaLoadScripts(%s): No run function\n", getScriptName(idx));
sid.state = SCRIPT_SYNTAX_ERROR;
initFunction = LUA_NOREF;
}
#if defined(LUA_MODEL_SCRIPTS)
// Get input/output tables for mixer scripts
@@ -908,6 +909,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
else {
TRACE_ERROR("luaLoadScripts(%s): The script did not return a table\n", getScriptName(idx));
sid.state = SCRIPT_SYNTAX_ERROR;
initFunction = LUA_NOREF;
}
// Pop the table off the stack
@@ -929,11 +931,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
else
TRACE_ERROR("luaLoadScripts(%s): %s\n", getScriptName(idx), lua_tostring(lsScripts, -1));
if (ref == SCRIPT_STANDALONE) {
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
luaError(lsScripts, sid.state, true);
return;
}
initFunction = LUA_NOREF;
// Replace the dead coroutine with a new one
lua_pop(L, 1); // Pop the dead coroutine off the main stack
@@ -944,6 +942,12 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
} while(initFunction != LUA_NOREF);
if (ref == SCRIPT_STANDALONE && sid.state != SCRIPT_OK) {
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
luaError(lsScripts, sid.state, true);
return;
}
} while(++ref < SCRIPT_STANDALONE);
// Loading has finished - start running scripts
@@ -981,7 +985,7 @@ static bool resumeLua(bool init, bool allowLcdUsage)
luaLcdAllowed = allowLcdUsage;
}
do {
for (; idx < luaScriptsCount; idx++) {
ScriptInternalData & sid = scriptInternalData[idx];
if (sid.state != SCRIPT_OK) continue;
@@ -1155,7 +1159,7 @@ static bool resumeLua(bool init, bool allowLcdUsage)
}
else luaFree(lsScripts, sid);
}
} while (++idx < luaScriptsCount);
} // for
// Toggle between background and foreground scripts
luaLcdAllowed = !luaLcdAllowed;