1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 17:55:19 +03:00

Lua garbage collector was never called. [Exit Long] will now force exit

on all standalone scripts.
This commit is contained in:
bsongis 2014-05-26 14:58:08 +02:00
parent e370b32203
commit 3f2fb96caa

View file

@ -252,6 +252,16 @@ static int luaLcdDrawText(lua_State *L)
return 0; return 0;
} }
static int luaLcdDrawNumber(lua_State *L)
{
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int n = luaL_checkinteger(L, 3);
int att = luaL_checkinteger(L, 4);
lcd_outdezAtt(x, y, n, att);
return 0;
}
static int luaLcdDrawSwitch(lua_State *L) static int luaLcdDrawSwitch(lua_State *L)
{ {
int x = luaL_checkinteger(L, 1); int x = luaL_checkinteger(L, 1);
@ -758,12 +768,12 @@ static int luaModelGetOutput(lua_State *L)
LimitData * limit = limitAddress(idx); LimitData * limit = limitAddress(idx);
lua_newtable(L); lua_newtable(L);
lua_pushtablezstring(L, "name", limit->name); lua_pushtablezstring(L, "name", limit->name);
lua_pushtablenumber(L, "min", limit->min); lua_pushtablenumber(L, "min", limit->min-1000);
lua_pushtablenumber(L, "max", limit->min); lua_pushtablenumber(L, "max", limit->max+1000);
lua_pushtablenumber(L, "offset", limit->offset); lua_pushtablenumber(L, "offset", limit->offset);
lua_pushtablenumber(L, "ppmCenter", limit->ppmCenter); lua_pushtablenumber(L, "ppmCenter", limit->ppmCenter);
lua_pushtableboolean(L, "symetrical", limit->symetrical); lua_pushtablenumber(L, "symetrical", limit->symetrical);
lua_pushtableboolean(L, "revert", limit->revert); lua_pushtablenumber(L, "revert", limit->revert);
if (limit->curve) if (limit->curve)
lua_pushtablenumber(L, "curve", limit->curve-1); lua_pushtablenumber(L, "curve", limit->curve-1);
else else
@ -789,10 +799,10 @@ static int luaModelSetOutput(lua_State *L)
str2zchar(limit->name, name, sizeof(limit->name)); str2zchar(limit->name, name, sizeof(limit->name));
} }
else if (!strcmp(key, "min")) { else if (!strcmp(key, "min")) {
limit->min = luaL_checkinteger(L, -1); limit->min = luaL_checkinteger(L, -1)+1000;
} }
else if (!strcmp(key, "max")) { else if (!strcmp(key, "max")) {
limit->max = luaL_checkinteger(L, -1); limit->max = luaL_checkinteger(L, -1)-1000;
} }
else if (!strcmp(key, "offset")) { else if (!strcmp(key, "offset")) {
limit->offset = luaL_checkinteger(L, -1); limit->offset = luaL_checkinteger(L, -1);
@ -967,6 +977,7 @@ static const luaL_Reg lcdLib[] = {
{ "drawLine", luaLcdDrawLine }, { "drawLine", luaLcdDrawLine },
{ "drawRectangle", luaLcdDrawRectangle }, { "drawRectangle", luaLcdDrawRectangle },
{ "drawText", luaLcdDrawText }, { "drawText", luaLcdDrawText },
{ "drawNumber", luaLcdDrawNumber },
{ "drawSwitch", luaLcdDrawSwitch }, { "drawSwitch", luaLcdDrawSwitch },
{ "drawSource", luaLcdDrawSource }, { "drawSource", luaLcdDrawSource },
{ "drawRect", luaLcdDrawRect }, { "drawRect", luaLcdDrawRect },
@ -1007,6 +1018,7 @@ void luaInit()
lua_registerint(L, "MIDSIZE", MIDSIZE); lua_registerint(L, "MIDSIZE", MIDSIZE);
lua_registerint(L, "SMLSIZE", SMLSIZE); lua_registerint(L, "SMLSIZE", SMLSIZE);
lua_registerint(L, "INVERS", INVERS); lua_registerint(L, "INVERS", INVERS);
lua_registerint(L, "PREC1", PREC1);
lua_registerint(L, "BLINK", BLINK); lua_registerint(L, "BLINK", BLINK);
lua_registerint(L, "VALUE", 0); lua_registerint(L, "VALUE", 0);
lua_registerint(L, "SOURCE", 1); lua_registerint(L, "SOURCE", 1);
@ -1024,6 +1036,10 @@ void luaInit()
lua_registerint(L, "EVT_EXIT_BREAK", EVT_KEY_BREAK(KEY_EXIT)); lua_registerint(L, "EVT_EXIT_BREAK", EVT_KEY_BREAK(KEY_EXIT));
lua_registerint(L, "EVT_PLUS_BREAK", EVT_KEY_BREAK(KEY_PLUS)); lua_registerint(L, "EVT_PLUS_BREAK", EVT_KEY_BREAK(KEY_PLUS));
lua_registerint(L, "EVT_MINUS_BREAK", EVT_KEY_BREAK(KEY_MINUS)); lua_registerint(L, "EVT_MINUS_BREAK", EVT_KEY_BREAK(KEY_MINUS));
lua_registerint(L, "EVT_PLUS_FIRST", EVT_KEY_FIRST(KEY_PLUS));
lua_registerint(L, "EVT_MINUS_FIRST", EVT_KEY_FIRST(KEY_MINUS));
lua_registerint(L, "EVT_PLUS_REPT", EVT_KEY_REPT(KEY_PLUS));
lua_registerint(L, "EVT_MINUS_REPT", EVT_KEY_REPT(KEY_MINUS));
lua_registerint(L, "FILL_WHITE", FILL_WHITE); lua_registerint(L, "FILL_WHITE", FILL_WHITE);
lua_registerint(L, "GREY_DEFAULT", GREY_DEFAULT); lua_registerint(L, "GREY_DEFAULT", GREY_DEFAULT);
lua_registerint(L, "SOLID", SOLID); lua_registerint(L, "SOLID", SOLID);
@ -1220,6 +1236,12 @@ void luaTask(uint8_t evt)
luaError(standaloneScript.state); luaError(standaloneScript.state);
} }
if (evt == EVT_KEY_LONG(KEY_EXIT)) {
TRACE("Script force exit");
killEvents(evt);
standaloneScript.state = SCRIPT_NOFILE;
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
}
} }
} }
else { else {
@ -1277,8 +1299,6 @@ void luaTask(uint8_t evt)
} }
} }
// TRACE("gc=%d", lua_gc(L, LUA_GCCOUNT, 0));
if (lua_gc(L, LUA_GCCOUNT, 0) > SCRIPTS_MAX_HEAP) { if (lua_gc(L, LUA_GCCOUNT, 0) > SCRIPTS_MAX_HEAP) {
uint8_t max_memory = 0; uint8_t max_memory = 0;
int8_t max_idx = -1; int8_t max_idx = -1;
@ -1296,4 +1316,8 @@ void luaTask(uint8_t evt)
} }
} }
} }
// TRACE("Before GC COLLECT gc=%d", lua_gc(L, LUA_GCCOUNT, 0));
lua_gc(L, LUA_GCCOLLECT, 0);
// TRACE("After GC COLLECT gc=%d", lua_gc(L, LUA_GCCOUNT, 0));
} }