diff --git a/radio/src/gui/colorlcd/standalone_lua.cpp b/radio/src/gui/colorlcd/standalone_lua.cpp index abe74cf81..4f4306977 100644 --- a/radio/src/gui/colorlcd/standalone_lua.cpp +++ b/radio/src/gui/colorlcd/standalone_lua.cpp @@ -156,17 +156,22 @@ void StandaloneLuaWindow::runLua(event_t evt) luaLcdBuffer = &lcdBuffer; TRACE("evt = 0x%x", evt); + + bool hasRun = luaTask(evt, true); + + if (luaState == INTERPRETER_RELOAD_PERMANENT_SCRIPTS) { + // Script does not run anymore... + TRACE("LUA standalone script exited: deleting window!"); + deleteLater(); + } - bool hasRun = luaTask(evt, RUN_STNDAL_SCRIPT, true); if (hasRun) { #if defined(DEBUG_WINDOWS) TRACE("# StandaloneLuaWindow::invalidate()"); #endif invalidate(); } else { - // Script does not run anymore... - TRACE("LUA standalone script exited: deleting window!"); - deleteLater(); + // The script was preempted, and the LCD should not be updated yet } // Kill global LUA LCD buffer diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 359135409..419019f67 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -912,15 +912,12 @@ static void luaLoadScripts(bool init, const char * filename = nullptr) if (initFunction != LUA_NOREF) TRACE_ERROR("luaLoadScripts(%s): init function: %s\n", getScriptName(idx), lua_tostring(lsScripts, -1)); - luaL_unref(lsScripts, LUA_REGISTRYINDEX, initFunction); - lua_settop(lsScripts, 0); - initFunction = LUA_NOREF; - } else + else TRACE_ERROR("luaLoadScripts(%s): %s\n", getScriptName(idx), lua_tostring(lsScripts, -1)); if (ref == SCRIPT_STANDALONE) { - luaError(lsScripts, sid.state); luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS; + luaError(lsScripts, sid.state, true); return; }