Lua: Use incremental GC and also call it for Widgets (#4369)

Fixes #3885: Error in Lua Widget options handled better (does not disable entire Lua state)
Disable Lua Widget if any of its functions has error.
This commit is contained in:
Damjan Adamic
2017-02-04 10:58:06 +01:00
committed by Bertrand Songis
parent d594843de2
commit b493973d7d
11 changed files with 213 additions and 89 deletions
+5
View File
@@ -79,6 +79,11 @@ class BitmapBufferBase
return data;
}
uint32_t getDataSize() const
{
return width * height * sizeof(T);
}
inline const display_t * getPixelPtr(coord_t x, coord_t y) const
{
#if defined(PCBX10)
+17
View File
@@ -176,6 +176,23 @@ int getOptionsCount(const ZoneOption * options)
template <class T>
bool menuSettings(const char * title, const T * object, uint32_t i_flags, event_t event)
{
if (object->getErrorMessage()) {
// display error instead of widget settings
// TODO nicer display (proper word-wrap)
SIMPLE_SUBMENU("Widget Error", ICON_MODEL_LUA_SCRIPTS, 1);
int len = strlen(object->getErrorMessage());
int y = 3*FH;
const char * p = object->getErrorMessage();
while (len > 0) {
lcdDrawSizedText(MENUS_MARGIN_LEFT, y, p, 30);
p += 30;
y += FH;
len -= 30;
}
return true;
}
const ZoneOption * options = object->getOptions();
linesCount = getOptionsCount(options);
uint8_t mstate_tab[MAX_WIDGET_OPTIONS];
+10
View File
@@ -139,6 +139,16 @@ bool menuStatsDebug(event_t event)
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+line*FH, "Lua interval");
lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+line*FH, 10*maxLuaInterval, LEFT, 0, NULL, "ms");
++line;
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+line*FH, "Lua memory");
lcdDrawText(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+line*FH+1, "[S]", HEADER_COLOR|SMLSIZE);
lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+line*FH, luaGetMemUsed(lsScripts), LEFT);
lcdDrawText(lcdNextPos+20, MENU_CONTENT_TOP+line*FH+1, "[W]", HEADER_COLOR|SMLSIZE);
lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+line*FH, luaGetMemUsed(lsWidgets), LEFT);
lcdDrawText(lcdNextPos+20, MENU_CONTENT_TOP+line*FH+1, "[B]", HEADER_COLOR|SMLSIZE);
lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+line*FH, luaExtraMemoryUsage, LEFT);
++line;
#endif
lcdDrawText(LCD_W/2, MENU_FOOTER_TOP+2, STR_MENUTORESET, CENTERED);
+5
View File
@@ -56,6 +56,11 @@ class Widget
inline const ZoneOption * getOptions() const;
virtual const char * getErrorMessage() const
{
return NULL;
}
inline ZoneOptionValue * getOptionValue(unsigned int index) const
{
return &persistentData->options[index];