@@ -55,8 +55,6 @@ extern "C" {
5555// #include "touch.h"
5656// #endif
5757
58- // Since we may not run FG every time, keep the events in a buffer
59- event_t events[EVENT_BUFFER_SIZE] = { 0 };
6058// The main thread - lsScripts is now a coroutine
6159lua_State * mainState = nullptr ;
6260lua_State *lsScripts = nullptr ;
@@ -327,14 +325,10 @@ void luaDoGc(lua_State * L, bool full)
327325void luaFree (lua_State * L, ScriptInternalData & sid)
328326{
329327 PROTECT_LUA () {
330- if (sid.run ) {
331- luaL_unref (L, LUA_REGISTRYINDEX, sid.run );
332- sid.run = 0 ;
333- }
334- if (sid.background ) {
335- luaL_unref (L, LUA_REGISTRYINDEX, sid.background );
336- sid.background = 0 ;
337- }
328+ luaL_unref (L, LUA_REGISTRYINDEX, sid.run );
329+ sid.run = LUA_REFNIL;
330+ luaL_unref (L, LUA_REGISTRYINDEX, sid.background );
331+ sid.background = LUA_REFNIL;
338332 }
339333 else {
340334 luaDisable ();
@@ -857,7 +851,7 @@ static int luaRegisterFunction(const char * key)
857851 TRACE_ERROR (" luaRegisterFunction(%s): Error: '%.*s' is not a function\n " , LEN_SCRIPT_FILENAME, getScriptName (luaScriptsCount - 1 ), key);
858852 }
859853 lua_pop (lsScripts, 1 );
860- return LUA_NOREF ;
854+ return LUA_REFNIL ;
861855 }
862856}
863857
@@ -877,7 +871,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
877871 if (luaState == INTERPRETER_PANIC) return ;
878872
879873 luaLcdAllowed = false ;
880- initFunction = LUA_NOREF ;
874+ initFunction = LUA_REFNIL ;
881875 luaEmptyEventBuffer ();
882876
883877 // Initialize loop over references
@@ -949,11 +943,11 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
949943 }
950944 else if (luaStatus == LUA_OK) {
951945 // Coroutine returned
952- if (initFunction != LUA_NOREF ) {
946+ if (initFunction != LUA_REFNIL ) {
953947 // init() returned - clean up
954948 luaL_unref (lsScripts, LUA_REGISTRYINDEX, initFunction);
955949 lua_settop (lsScripts, 0 );
956- initFunction = LUA_NOREF ;
950+ initFunction = LUA_REFNIL ;
957951 }
958952 else {
959953 // chunk() returned
@@ -964,10 +958,10 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
964958 sid.run = luaRegisterFunction (" run" );
965959 sid.background = luaRegisterFunction (" background" );
966960 initFunction = luaRegisterFunction (" init" );
967- if (sid.run == LUA_NOREF ) {
961+ if (sid.run == LUA_REFNIL ) {
968962 snprintf (lua_warning_info, LUA_WARNING_INFO_LEN, " luaLoadScripts(%.*s): No run function\n " , LEN_SCRIPT_FILENAME, getScriptName (idx));
969963 sid.state = SCRIPT_SYNTAX_ERROR;
970- initFunction = LUA_NOREF ;
964+ initFunction = LUA_REFNIL ;
971965 }
972966#if defined(LUA_MODEL_SCRIPTS)
973967 // Get input/output tables for mixer scripts
@@ -985,14 +979,14 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
985979 else {
986980 snprintf (lua_warning_info, LUA_WARNING_INFO_LEN, " luaLoadScripts(%.*s): The script did not return a table\n " , LEN_SCRIPT_FILENAME, getScriptName (idx));
987981 sid.state = SCRIPT_SYNTAX_ERROR;
988- initFunction = LUA_NOREF ;
982+ initFunction = LUA_REFNIL ;
989983 }
990984
991985 // Pop the table off the stack
992986 lua_pop (lsScripts, 1 );
993987
994988 // If init(), push it on the stack
995- if (initFunction != LUA_NOREF ) {
989+ if (initFunction != LUA_REFNIL ) {
996990 lua_rawgeti (lsScripts, LUA_REGISTRYINDEX, initFunction);
997991#if !defined(COLORLCD)
998992 if (ref == SCRIPT_STANDALONE) {
@@ -1005,9 +999,9 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
1005999 else {
10061000 // Error
10071001 sid.state = SCRIPT_SYNTAX_ERROR;
1008- initFunction = LUA_NOREF ;
1002+ initFunction = LUA_REFNIL ;
10091003 }
1010- } while (initFunction != LUA_NOREF );
1004+ } while (initFunction != LUA_REFNIL );
10111005
10121006 if (sid.state != SCRIPT_OK) {
10131007 luaError (lsScripts, sid.state );
@@ -1149,14 +1143,14 @@ static bool resumeLua(bool init, bool allowLcdUsage)
11491143 functionsContext->lastFunctionTime [idx] = tmr10ms;
11501144 }
11511145 else {
1152- if (sid.background == LUA_NOREF ) continue ;
1146+ if (sid.background == LUA_REFNIL ) continue ;
11531147 lua_rawgeti (lsScripts, LUA_REGISTRYINDEX, sid.background );
11541148 }
11551149 } else continue ;
11561150 }
11571151#if defined(PCBTARANIS)
11581152 else if (ref <= SCRIPT_TELEMETRY_LAST) {
1159- if (sid.background == LUA_NOREF ) continue ;
1153+ if (sid.background == LUA_REFNIL ) continue ;
11601154 lua_rawgeti (lsScripts, LUA_REGISTRYINDEX, sid.background );
11611155 }
11621156#endif
0 commit comments