From 274ab44399adf09ddce4607160512aa5b5c03036 Mon Sep 17 00:00:00 2001 From: raphaelcoeffic Date: Tue, 3 Jan 2023 18:34:01 +0100 Subject: [PATCH 1/2] chore(lua): revert useless c light function change This change was part of the eLua LTR patches (based on 5.1), whereby this feature was already integrated in Lua 5.2. --- radio/src/thirdparty/Lua/src/lapi.c | 30 +++++-------------------- radio/src/thirdparty/Lua/src/ldo.c | 5 +---- radio/src/thirdparty/Lua/src/lobject.h | 9 ++------ radio/src/thirdparty/Lua/src/lrotable.c | 2 +- radio/src/thirdparty/Lua/src/ltable.c | 7 +----- radio/src/thirdparty/Lua/src/ltm.c | 2 +- radio/src/thirdparty/Lua/src/lua.h | 18 +++++++-------- radio/src/thirdparty/Lua/src/lundump.c | 10 ++++----- radio/src/thirdparty/Lua/src/lvm.c | 5 ++--- 9 files changed, 27 insertions(+), 61 deletions(-) diff --git a/radio/src/thirdparty/Lua/src/lapi.c b/radio/src/thirdparty/Lua/src/lapi.c index 2d95f28edf8..50d2a3b7e24 100644 --- a/radio/src/thirdparty/Lua/src/lapi.c +++ b/radio/src/thirdparty/Lua/src/lapi.c @@ -261,7 +261,7 @@ LUA_API const char *lua_typename (lua_State *L, int t) { LUA_API int lua_iscfunction (lua_State *L, int idx) { StkId o = index2addr(L, idx); - return (ttislcf(o) || ttislightfunction(o) || (ttisCclosure(o))); + return (ttislcf(o) || (ttisCclosure(o))); } @@ -418,7 +418,7 @@ LUA_API size_t lua_rawlen (lua_State *L, int idx) { LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { StkId o = index2addr(L, idx); - if (ttislcf(o)) return lcfvalue(o); + if (ttislcf(o)) return fvalue(o); else if (ttisCclosure(o)) return clCvalue(o)->f; else return NULL; /* not a C function */ @@ -447,13 +447,12 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { case LUA_TTABLE: return hvalue(o); case LUA_TLCL: return clLvalue(o); case LUA_TCCL: return clCvalue(o); - case LUA_TLCF: return cast(void *, cast(size_t, lcfvalue(o))); + case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o))); case LUA_TTHREAD: return thvalue(o); case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA: return lua_touserdata(L, idx); case LUA_TROTABLE: - case LUA_TLIGHTFUNCTION: return pvalue(o); default: return NULL; } @@ -558,7 +557,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { lua_lock(L); if (n == 0) { - setlcfvalue(L->top, fn); + setfvalue(L->top, fn); } else { Closure *cl; @@ -598,13 +597,6 @@ LUA_API void lua_pushrotable (lua_State *L, void *p) { lua_unlock(L); } -LUA_API void lua_pushlightfunction(lua_State *L, void *p) { - lua_lock(L); - setlfvalue(L->top, p); - api_incr_top(L); - lua_unlock(L); -} - LUA_API int lua_pushthread (lua_State *L) { lua_lock(L); setthvalue(L, L->top, L); @@ -619,24 +611,14 @@ LUA_API int lua_pushthread (lua_State *L) { LUA_API void lua_getglobal (lua_State *L, const char *var) { - TValue value; - luaR_result found; - TRACE_LUA_INTERNALS("lua_getglobal() '%s'", var); Table *reg = hvalue(&G(L)->l_registry); const TValue *gt; /* global table */ lua_lock(L); - - found = luaR_findglobal(L, var, &value); - if (found && ttislightfunction(&value)) { - setsvalue2s(L, L->top++, luaS_new(L, var)); - setlfvalue(L->top - 1, lfvalue(&value)) - } - else { + setsvalue2s(L, L->top++, luaS_new(L, var)); + if (!luaR_findglobal(L, var, L->top - 1)) { gt = luaH_getint(reg, LUA_RIDX_GLOBALS); - setsvalue2s(L, L->top++, luaS_new(L, var)); luaV_gettable(L, gt, L->top - 1, L->top - 1); } - lua_unlock(L); } diff --git a/radio/src/thirdparty/Lua/src/ldo.c b/radio/src/thirdparty/Lua/src/ldo.c index 626e3715916..70ad81b89a0 100644 --- a/radio/src/thirdparty/Lua/src/ldo.c +++ b/radio/src/thirdparty/Lua/src/ldo.c @@ -305,10 +305,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { ptrdiff_t funcr = savestack(L, func); switch (ttype(func)) { case LUA_TLCF: /* light C function */ - f = lcfvalue(func); - goto Cfunc; - case LUA_TLIGHTFUNCTION: - f = check_exp(ttislightfunction(func), val_(func).f); + f = fvalue(func); goto Cfunc; case LUA_TCCL: { /* C closure */ f = clCvalue(func)->f; diff --git a/radio/src/thirdparty/Lua/src/lobject.h b/radio/src/thirdparty/Lua/src/lobject.h index 919b2c304fa..ff421aeef82 100644 --- a/radio/src/thirdparty/Lua/src/lobject.h +++ b/radio/src/thirdparty/Lua/src/lobject.h @@ -134,7 +134,6 @@ typedef union Value Value; #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) #define ttisrotable(o) checktag((o), LUA_TROTABLE) -#define ttislightfunction(o) checktag((o), LUA_TLIGHTFUNCTION) #define ttisstring(o) checktype((o), LUA_TSTRING) #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) @@ -155,7 +154,6 @@ typedef union Value Value; #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) #define rvalue(o) check_exp(ttisrotable(o), val_(o).p) -#define lfvalue(o) check_exp(ttislightfunction(o), val_(o).p) #define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts) #define tsvalue(o) (&rawtsvalue(o)->tsv) #define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u) @@ -163,7 +161,7 @@ typedef union Value Value; #define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl) #define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l) #define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c) -#define lcfvalue(o) check_exp(ttislcf(o), val_(o).f) +#define fvalue(o) check_exp(ttislcf(o), val_(o).f) #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) @@ -192,7 +190,7 @@ typedef union Value Value; #define setnilvalue(obj) settt_(obj, LUA_TNIL) -#define setlcfvalue(obj,x) \ +#define setfvalue(obj,x) \ { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); } #define setpvalue(obj,x) \ @@ -201,9 +199,6 @@ typedef union Value Value; #define setrvalue(obj,x) \ { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TROTABLE); } -#define setlfvalue(obj,x) \ - { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTFUNCTION); } - #define setbvalue(obj,x) \ { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } diff --git a/radio/src/thirdparty/Lua/src/lrotable.c b/radio/src/thirdparty/Lua/src/lrotable.c index 838536bc2e3..b92d5ef9a8b 100644 --- a/radio/src/thirdparty/Lua/src/lrotable.c +++ b/radio/src/thirdparty/Lua/src/lrotable.c @@ -15,7 +15,7 @@ static luaR_result luaR_findfunctionkey(const luaL_Reg* pf, const char * key, TV if (!pf->name) break; if (!strcmp(pf->name, key)) { - setlfvalue(found, pf->func); + setfvalue(found, pf->func); return 1; } pf++; diff --git a/radio/src/thirdparty/Lua/src/ltable.c b/radio/src/thirdparty/Lua/src/ltable.c index 902e09fae98..c9fd21d4bd3 100644 --- a/radio/src/thirdparty/Lua/src/ltable.c +++ b/radio/src/thirdparty/Lua/src/ltable.c @@ -113,7 +113,7 @@ static Node *mainposition (const Table *t, const TValue *key) { case LUA_TLIGHTUSERDATA: return hashpointer(t, pvalue(key)); case LUA_TLCF: - return hashpointer(t, lcfvalue(key)); + return hashpointer(t, fvalue(key)); default: return hashpointer(t, gcvalue(key)); } @@ -209,10 +209,6 @@ static int computesizes (int nums[], int *narray) { } if (a == *narray) break; /* all elements already counted */ } - if (n - *narray > 1024) - *narray += 1024; - else - *narray = n; lua_assert(*narray/2 <= na && na <= *narray); return na; } @@ -306,7 +302,6 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { int i; int oldasize = t->sizearray; int oldhsize = t->lsizenode; - TRACE_LUA_INTERNALS_WITH_LINEINFO(L, "luaH_resize table %p %d(%d) %d(%d)", t, nasize, oldasize, nhsize, twoto(oldhsize)); Node *nold = t->node; /* save old hash ... */ if (nasize > oldasize) /* array part must grow? */ setarrayvector(L, t, nasize); diff --git a/radio/src/thirdparty/Lua/src/ltm.c b/radio/src/thirdparty/Lua/src/ltm.c index a06cb79e472..d738b083481 100644 --- a/radio/src/thirdparty/Lua/src/ltm.c +++ b/radio/src/thirdparty/Lua/src/ltm.c @@ -23,7 +23,7 @@ static const char udatatypename[] = "userdata"; LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { "no value", - "nil", "boolean", "rotable", "lightfunction", udatatypename, "number", + "nil", "boolean", "rotable", udatatypename, "number", "string", "table", "function", udatatypename, "thread", "proto", "upval" /* these last two cases are used for tests only */ }; diff --git a/radio/src/thirdparty/Lua/src/lua.h b/radio/src/thirdparty/Lua/src/lua.h index cf4af4634bb..967bb6d3b2f 100644 --- a/radio/src/thirdparty/Lua/src/lua.h +++ b/radio/src/thirdparty/Lua/src/lua.h @@ -78,16 +78,15 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); #define LUA_TNIL 0 #define LUA_TBOOLEAN 1 #define LUA_TROTABLE 2 -#define LUA_TLIGHTFUNCTION 3 -#define LUA_TLIGHTUSERDATA 4 -#define LUA_TNUMBER 5 -#define LUA_TSTRING 6 -#define LUA_TTABLE 7 -#define LUA_TFUNCTION 8 -#define LUA_TUSERDATA 9 -#define LUA_TTHREAD 10 +#define LUA_TLIGHTUSERDATA 3 +#define LUA_TNUMBER 4 +#define LUA_TSTRING 5 +#define LUA_TTABLE 6 +#define LUA_TFUNCTION 7 +#define LUA_TUSERDATA 8 +#define LUA_TTHREAD 9 -#define LUA_NUMTAGS 11 +#define LUA_NUMTAGS 10 @@ -216,7 +215,6 @@ LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); LUA_API void (lua_pushboolean) (lua_State *L, int b); LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); -LUA_API void (lua_pushlightfunction) (lua_State *L, void *p); LUA_API void (lua_pushrotable) (lua_State *L, void *p); LUA_API int (lua_pushthread) (lua_State *L); diff --git a/radio/src/thirdparty/Lua/src/lundump.c b/radio/src/thirdparty/Lua/src/lundump.c index a1dd1213f53..d732d6f607a 100644 --- a/radio/src/thirdparty/Lua/src/lundump.c +++ b/radio/src/thirdparty/Lua/src/lundump.c @@ -69,7 +69,7 @@ static lua_Number LoadNumber(LoadState* S) return x; } -static TString* Load_String(LoadState* S) +static TString* LoadString(LoadState* S) { size_t size; LoadVar(S,size); @@ -116,7 +116,7 @@ static void LoadConstants(LoadState* S, Proto* f) setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: - setsvalue2n(S->L,o,Load_String(S)); + setsvalue2n(S->L,o,LoadString(S)); break; default: lua_assert(0); } @@ -149,7 +149,7 @@ static void LoadUpvalues(LoadState* S, Proto* f) static void LoadDebug(LoadState* S, Proto* f) { int i,n; - f->source=Load_String(S); + f->source=LoadString(S); n=LoadInt(S); f->lineinfo=luaM_newvector(S->L,n,int); f->sizelineinfo=n; @@ -160,12 +160,12 @@ static void LoadDebug(LoadState* S, Proto* f) for (i=0; ilocvars[i].varname=NULL; for (i=0; ilocvars[i].varname=Load_String(S); + f->locvars[i].varname=LoadString(S); f->locvars[i].startpc=LoadInt(S); f->locvars[i].endpc=LoadInt(S); } n=LoadInt(S); - for (i=0; iupvalues[i].name=Load_String(S); + for (i=0; iupvalues[i].name=LoadString(S); } static void LoadFunction(LoadState* S, Proto* f) diff --git a/radio/src/thirdparty/Lua/src/lvm.c b/radio/src/thirdparty/Lua/src/lvm.c index d4bb2381be7..442e5d44dde 100644 --- a/radio/src/thirdparty/Lua/src/lvm.c +++ b/radio/src/thirdparty/Lua/src/lvm.c @@ -142,7 +142,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { luaG_typeerror(L, t, "index"); } - if (ttisfunction(tm) || ttislightfunction(tm)) { + if (ttisfunction(tm)) { callTM(L, tm, t, key, val, 1); return; } @@ -285,9 +285,8 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) { case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case LUA_TLIGHTUSERDATA: case LUA_TROTABLE: - case LUA_TLIGHTFUNCTION: return pvalue(t1) == pvalue(t2); - case LUA_TLCF: return lcfvalue(t1) == lcfvalue(t2); + case LUA_TLCF: return fvalue(t1) == fvalue(t2); case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2)); case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2)); case LUA_TUSERDATA: { From a7c36f407e80b90d123bfff5845f85adbe95b40e Mon Sep 17 00:00:00 2001 From: raphaelcoeffic Date: Tue, 3 Jan 2023 18:02:00 +0100 Subject: [PATCH 2/2] feat(lua): port of NodeMCU Lua53 read-only tables --- radio/src/lua/CMakeLists.txt | 1 - radio/src/lua/api_colorlcd.cpp | 125 ++-- radio/src/lua/api_colorlcd.h | 25 +- radio/src/lua/api_filesystem.cpp | 34 +- radio/src/lua/api_filesystem.h | 8 +- radio/src/lua/api_general.cpp | 770 +++++++++---------- radio/src/lua/api_lcd.cpp | 949 ------------------------ radio/src/lua/api_model.cpp | 77 +- radio/src/lua/api_stdlcd.cpp | 45 +- radio/src/lua/interface.cpp | 41 +- radio/src/lua/lua_api.h | 27 +- radio/src/lua/lua_widget.cpp | 1 - radio/src/lua/lua_widget_factory.cpp | 1 - radio/src/lua/widgets.cpp | 14 +- radio/src/thirdparty/Lua/src/lapi.c | 46 +- radio/src/thirdparty/Lua/src/lauxlib.c | 44 +- radio/src/thirdparty/Lua/src/lauxlib.h | 6 + radio/src/thirdparty/Lua/src/lbaselib.c | 84 ++- radio/src/thirdparty/Lua/src/lbitlib.c | 38 +- radio/src/thirdparty/Lua/src/linit.c | 143 ++-- radio/src/thirdparty/Lua/src/liolib.c | 91 +-- radio/src/thirdparty/Lua/src/llimits.h | 11 + radio/src/thirdparty/Lua/src/lmathlib.c | 77 +- radio/src/thirdparty/Lua/src/lobject.h | 53 +- radio/src/thirdparty/Lua/src/lro_defs.h | 52 ++ radio/src/thirdparty/Lua/src/lrotable.c | 106 --- radio/src/thirdparty/Lua/src/lrotable.h | 46 -- radio/src/thirdparty/Lua/src/lstate.c | 21 + radio/src/thirdparty/Lua/src/lstate.h | 15 +- radio/src/thirdparty/Lua/src/lstrlib.c | 60 +- radio/src/thirdparty/Lua/src/ltable.c | 163 +++- radio/src/thirdparty/Lua/src/ltable.h | 5 + radio/src/thirdparty/Lua/src/ltm.c | 2 +- radio/src/thirdparty/Lua/src/lua.h | 27 +- radio/src/thirdparty/Lua/src/luaconf.h | 17 +- radio/src/thirdparty/Lua/src/lvm.c | 68 +- 36 files changed, 1241 insertions(+), 2052 deletions(-) delete mode 100644 radio/src/lua/api_lcd.cpp create mode 100644 radio/src/thirdparty/Lua/src/lro_defs.h delete mode 100644 radio/src/thirdparty/Lua/src/lrotable.c delete mode 100644 radio/src/thirdparty/Lua/src/lrotable.h diff --git a/radio/src/lua/CMakeLists.txt b/radio/src/lua/CMakeLists.txt index add5fc72092..938e8a2cd06 100644 --- a/radio/src/lua/CMakeLists.txt +++ b/radio/src/lua/CMakeLists.txt @@ -56,7 +56,6 @@ set(LUA_SRC lstate.c lstring.c ltable.c - lrotable.c ltm.c lundump.c lvm.c diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index 57d60657c69..2776be17b24 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -19,13 +19,24 @@ * GNU General Public License for more details. */ +#define LUA_LIB + #include #include + #include "opentx.h" #include "libopenui.h" #include "widget.h" + +#include "lua_api.h" #include "api_colorlcd.h" +#define BITMAP_METATABLE "BITMAP*" + +constexpr coord_t INVERT_BOX_MARGIN = 2; +constexpr int8_t text_horizontal_offset[7] {-2,-1,-2,-2,-2,-2,-2}; +constexpr int8_t text_vertical_offset[7] {0,0,0,0,0,-1,7}; + BitmapBuffer* luaLcdBuffer = nullptr; Widget* runningFS = nullptr; @@ -499,8 +510,6 @@ static int luaLcdDrawSource(lua_State *L) return 0; } -#define LUA_BITMAPHANDLE "BITMAP*" - /*luadoc @function Bitmap.open(name) @@ -547,7 +556,7 @@ static int luaOpenBitmap(lua_State *L) TRACE("luaOpenBitmap: %p (%u)", *b, size); } - luaL_getmetatable(L, LUA_BITMAPHANDLE); + luaL_getmetatable(L, BITMAP_METATABLE); lua_setmetatable(L, -2); return 1; @@ -555,7 +564,7 @@ static int luaOpenBitmap(lua_State *L) static BitmapBuffer * checkBitmap(lua_State * L, int index) { - BitmapBuffer ** b = (BitmapBuffer **)luaL_checkudata(L, index, LUA_BITMAPHANDLE); + BitmapBuffer ** b = (BitmapBuffer **)luaL_checkudata(L, index, BITMAP_METATABLE); return *b; } @@ -633,7 +642,7 @@ static int luaBitmapResize(lua_State * L) TRACE("luaResizeBitmap: %p (%u)", *n, size); } - luaL_getmetatable(L, LUA_BITMAPHANDLE); + luaL_getmetatable(L, BITMAP_METATABLE); lua_setmetatable(L, -2); return 1; @@ -683,23 +692,6 @@ static int luaDestroyBitmap(lua_State * L) return 0; } -const luaL_Reg bitmapFuncs[] = { - { "open", luaOpenBitmap }, - { "getSize", luaGetBitmapSize }, - { "resize", luaBitmapResize }, - { "toMask", luaBitmapTo8bitMask }, - { "__gc", luaDestroyBitmap }, - { NULL, NULL } -}; - -void registerBitmapClass(lua_State * L) -{ - luaL_newmetatable(L, LUA_BITMAPHANDLE); - luaL_setfuncs(L, bitmapFuncs, 0); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - lua_setglobal(L, "Bitmap"); -} /*luadoc @function lcd.drawBitmap(bitmap, x, y [, scale]) @@ -1427,39 +1419,56 @@ static int luaLcdExitFullScreen(lua_State *L) return 0; } -const luaL_Reg lcdLib[] = { - { "refresh", luaLcdRefresh }, - { "clear", luaLcdClear }, - { "resetBacklightTimeout", luaLcdResetBacklightTimeout }, - { "drawPoint", luaLcdDrawPoint }, - { "drawLine", luaLcdDrawLine }, - { "drawRectangle", luaLcdDrawRectangle }, - { "drawFilledRectangle", luaLcdDrawFilledRectangle }, - { "invertRect", luaLcdInvertRect }, - { "drawText", luaLcdDrawText }, - { "drawTextLines", luaLcdDrawTextLines }, - { "sizeText", luaLcdSizeText }, - { "drawTimer", luaLcdDrawTimer }, - { "drawNumber", luaLcdDrawNumber }, - { "drawChannel", luaLcdDrawChannel }, - { "drawSwitch", luaLcdDrawSwitch }, - { "drawSource", luaLcdDrawSource }, - { "drawGauge", luaLcdDrawGauge }, - { "drawBitmap", luaLcdDrawBitmap }, - { "drawBitmapPattern", luaLcdDrawBitmapPattern }, - { "drawBitmapPatternPie", luaLcdDrawBitmapPatternPie }, - { "setColor", luaLcdSetColor }, - { "getColor", luaLcdGetColor }, - { "RGB", luaRGB }, - { "drawCircle", luaLcdDrawCircle }, - { "drawFilledCircle", luaLcdDrawFilledCircle }, - { "drawTriangle", luaLcdDrawTriangle }, - { "drawFilledTriangle", luaLcdDrawFilledTriangle }, - { "drawArc", luaLcdDrawArc }, - { "drawPie", luaLcdDrawPie }, - { "drawAnnulus", luaLcdDrawAnnulus }, - { "drawLineWithClipping", luaLcdDrawLineWithClipping }, - { "drawHudRectangle", luaLcdDrawHudRectangle }, - { "exitFullScreen", luaLcdExitFullScreen }, - { NULL, NULL } /* sentinel */ -}; +LROT_BEGIN(lcdlib, NULL, 0) + LROT_FUNCENTRY( refresh, luaLcdRefresh ) + LROT_FUNCENTRY( clear, luaLcdClear ) + LROT_FUNCENTRY( resetBacklightTimeout, luaLcdResetBacklightTimeout ) + LROT_FUNCENTRY( drawPoint, luaLcdDrawPoint ) + LROT_FUNCENTRY( drawLine, luaLcdDrawLine ) + LROT_FUNCENTRY( drawRectangle, luaLcdDrawRectangle ) + LROT_FUNCENTRY( drawFilledRectangle, luaLcdDrawFilledRectangle ) + LROT_FUNCENTRY( invertRect, luaLcdInvertRect ) + LROT_FUNCENTRY( drawText, luaLcdDrawText ) + LROT_FUNCENTRY( drawTextLines, luaLcdDrawTextLines ) + LROT_FUNCENTRY( sizeText, luaLcdSizeText ) + LROT_FUNCENTRY( drawTimer, luaLcdDrawTimer ) + LROT_FUNCENTRY( drawNumber, luaLcdDrawNumber ) + LROT_FUNCENTRY( drawChannel, luaLcdDrawChannel ) + LROT_FUNCENTRY( drawSwitch, luaLcdDrawSwitch ) + LROT_FUNCENTRY( drawSource, luaLcdDrawSource ) + LROT_FUNCENTRY( drawGauge, luaLcdDrawGauge ) + LROT_FUNCENTRY( drawBitmap, luaLcdDrawBitmap ) + LROT_FUNCENTRY( drawBitmapPattern, luaLcdDrawBitmapPattern ) + LROT_FUNCENTRY( drawBitmapPatternPie, luaLcdDrawBitmapPatternPie ) + LROT_FUNCENTRY( setColor, luaLcdSetColor ) + LROT_FUNCENTRY( getColor, luaLcdGetColor ) + LROT_FUNCENTRY( RGB, luaRGB ) + LROT_FUNCENTRY( drawCircle, luaLcdDrawCircle ) + LROT_FUNCENTRY( drawFilledCircle, luaLcdDrawFilledCircle ) + LROT_FUNCENTRY( drawTriangle, luaLcdDrawTriangle ) + LROT_FUNCENTRY( drawFilledTriangle, luaLcdDrawFilledTriangle ) + LROT_FUNCENTRY( drawArc, luaLcdDrawArc ) + LROT_FUNCENTRY( drawPie, luaLcdDrawPie ) + LROT_FUNCENTRY( drawAnnulus, luaLcdDrawAnnulus ) + LROT_FUNCENTRY( drawLineWithClipping, luaLcdDrawLineWithClipping ) + LROT_FUNCENTRY( drawHudRectangle, luaLcdDrawHudRectangle ) + LROT_FUNCENTRY( exitFullScreen, luaLcdExitFullScreen ) +LROT_END(lcdlib, NULL, 0) + +LROT_BEGIN(bitmap_mt, NULL, LROT_MASK_GC) + LROT_FUNCENTRY( __gc, luaDestroyBitmap ) + LROT_FUNCENTRY( getSize, luaGetBitmapSize ) + LROT_FUNCENTRY( resize, luaBitmapResize ) + LROT_FUNCENTRY( toMask, luaBitmapTo8bitMask ) +LROT_END(bitmap_mt, NULL, LROT_MASK_GC) + +LROT_BEGIN(bitmaplib, NULL, 0) + LROT_FUNCENTRY( open, luaOpenBitmap ) +LROT_END(bitmaplib, NULL, 0) + +extern "C" { + LUALIB_API int luaopen_bitmap(lua_State * L) { + luaL_rometatable( L, BITMAP_METATABLE, LROT_TABLEREF(bitmap_mt)); + return 0; + } +} diff --git a/radio/src/lua/api_colorlcd.h b/radio/src/lua/api_colorlcd.h index 32b6d7d57ea..d727ce0bb0e 100644 --- a/radio/src/lua/api_colorlcd.h +++ b/radio/src/lua/api_colorlcd.h @@ -19,27 +19,6 @@ * GNU General Public License for more details. */ -// -// Obsoleted definitions: -// -> please check against libopenui_defines.h for conflicts -// -> here we use the 4 most significant bits for our flags (32 bit unsigned) -// -// INVERS & BLINK are used in most scripts, let's offer a compatibility mode. -// -#undef INVERS -#undef BLINK +#include "definitions.h" -#define INVERS 0x01u -#define BLINK 0x1000u -#define RGB_FLAG 0x8000u - -constexpr coord_t INVERT_BOX_MARGIN = 2; - -constexpr int8_t text_horizontal_offset[7] {-2,-1,-2,-2,-2,-2,-2}; -constexpr int8_t text_vertical_offset[7] {0,0,0,0,0,-1,7}; - -extern bool luaLcdAllowed; -extern BitmapBuffer * luaLcdBuffer; -extern Widget * runningFS; - -LcdFlags flagsRGB(LcdFlags flags); +EXTERN_C(LUALIB_API int luaopen_bitmap(lua_State * L)); diff --git a/radio/src/lua/api_filesystem.cpp b/radio/src/lua/api_filesystem.cpp index a857d81d058..1392cba116e 100644 --- a/radio/src/lua/api_filesystem.cpp +++ b/radio/src/lua/api_filesystem.cpp @@ -19,10 +19,11 @@ * GNU General Public License for more details. */ +#define LUA_LIB #include -#include "lua_api.h" +#include "lua_api.h" #include "api_filesystem.h" // garbage collector for luaDir @@ -33,18 +34,6 @@ static int dir_gc(lua_State* L) return 0; } -void registerDirIter(lua_State* L) -{ - luaL_newmetatable(L, DIR_METATABLE); - - /* set the garbage colector field */ - lua_pushstring(L, "__gc"); - lua_pushcfunction(L, dir_gc); - lua_settable(L, -3); - - lua_pop(L, 1); -} - static int dir_iter(lua_State* L) { DIR* dir = (DIR*)lua_touserdata(L, lua_upvalueindex(1)); @@ -160,4 +149,21 @@ int luaFstat(lua_State* L) lua_settable(L, -3); return 1; -} \ No newline at end of file +} + + +LROT_BEGIN(dir_handle, NULL, LROT_MASK_GC) + LROT_FUNCENTRY( __gc, dir_gc ) +LROT_END(dir_handle, NULL, LROT_MASK_GC) + +LROT_BEGIN(etxdir, NULL, 0) + LROT_FUNCENTRY( dir, luaDir ) + LROT_FUNCENTRY( fstat, luaFstat ) +LROT_END(etxdir, NULL, 0) + +extern "C" { + LUAMOD_API int luaopen_etxdir(lua_State* L) { + luaL_rometatable( L, DIR_METATABLE, LROT_TABLEREF(dir_handle)); + return 0; + } +} diff --git a/radio/src/lua/api_filesystem.h b/radio/src/lua/api_filesystem.h index 7c1dd8c19c7..55e5ca6f7d7 100644 --- a/radio/src/lua/api_filesystem.h +++ b/radio/src/lua/api_filesystem.h @@ -19,8 +19,8 @@ * GNU General Public License for more details. */ -#define DIR_METATABLE "directory metatable" +#include "definitions.h" -void registerDirIter(lua_State* L); -int luaDir(lua_State* L); -int luaFstat(lua_State* L); \ No newline at end of file +#define DIR_METATABLE "DIR*" + +EXTERN_C(LUALIB_API int luaopen_etxdir(lua_State* L)); diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 9e5b717902d..fc1d92eaf1b 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -19,6 +19,8 @@ * GNU General Public License for more details. */ +#define LUA_LIB + #include #include #include "opentx.h" @@ -58,12 +60,6 @@ #define FIND_FIELD_DESC 0x01 -#define KEY_EVENTS(xxx, yyy) \ - { "EVT_"#xxx"_FIRST", EVT_KEY_FIRST(yyy) }, \ - { "EVT_"#xxx"_BREAK", EVT_KEY_BREAK(yyy) }, \ - { "EVT_"#xxx"_LONG", EVT_KEY_LONG(yyy) }, \ - { "EVT_"#xxx"_REPT", EVT_KEY_REPT(yyy) } - // see strhelpers.cpp for pre-instantiation of function-template // getSourceString() for this parametrization static constexpr uint8_t maxSourceNameLength{16}; @@ -2664,125 +2660,131 @@ static int luaGetTrainerStatus(lua_State * L) return 1; } -const luaL_Reg opentxLib[] = { - { "getTime", luaGetTime }, - { "getDateTime", luaGetDateTime }, + +#define KEY_EVENTS(xxx, yyy) \ + { "EVT_"#xxx"_FIRST", LRO_NUMVAL(EVT_KEY_FIRST(yyy)) }, \ + { "EVT_"#xxx"_BREAK", LRO_NUMVAL(EVT_KEY_BREAK(yyy)) }, \ + { "EVT_"#xxx"_LONG", LRO_NUMVAL(EVT_KEY_LONG(yyy)) }, \ + { "EVT_"#xxx"_REPT", LRO_NUMVAL(EVT_KEY_REPT(yyy)) }, + +LROT_BEGIN(etxlib, NULL, 0) + LROT_FUNCENTRY( getTime, luaGetTime ) + LROT_FUNCENTRY( getDateTime, luaGetDateTime ) #if defined(RTCLOCK) - { "getRtcTime", luaGetRtcTime }, + LROT_FUNCENTRY( getRtcTime, luaGetRtcTime ) #endif - { "getVersion", luaGetVersion }, - { "getGeneralSettings", luaGetGeneralSettings }, - { "getGlobalTimer", luaGetGlobalTimer }, - { "getRotEncSpeed", luaGetRotEncSpeed }, - { "getRotEncMode", luaGetRotEncMode }, - { "getValue", luaGetValue }, - { "getOutputValue", luaGetOutputValue }, - { "getSourceValue", luaGetSourceValue }, - { "getTrainerStatus", luaGetTrainerStatus }, - { "getRAS", luaGetRAS }, - { "getTxGPS", luaGetTxGPS }, - { "getFieldInfo", luaGetFieldInfo }, - { "getSourceInfo", luaGetFieldInfo }, - { "getFlightMode", luaGetFlightMode }, - { "playFile", luaPlayFile }, - { "playNumber", luaPlayNumber }, - { "playDuration", luaPlayDuration }, - { "playTone", luaPlayTone }, - { "playHaptic", luaPlayHaptic }, - { "flushAudio", luaFlushAudio }, + LROT_FUNCENTRY( getVersion, luaGetVersion ) + LROT_FUNCENTRY( getGeneralSettings, luaGetGeneralSettings ) + LROT_FUNCENTRY( getGlobalTimer, luaGetGlobalTimer ) + LROT_FUNCENTRY( getRotEncSpeed, luaGetRotEncSpeed ) + LROT_FUNCENTRY( getRotEncMode, luaGetRotEncMode ) + LROT_FUNCENTRY( getValue, luaGetValue ) + LROT_FUNCENTRY( getOutputValue, luaGetOutputValue ) + LROT_FUNCENTRY( getSourceValue, luaGetSourceValue ) + LROT_FUNCENTRY( getTrainerStatus, luaGetTrainerStatus ) + LROT_FUNCENTRY( getRAS, luaGetRAS ) + LROT_FUNCENTRY( getTxGPS, luaGetTxGPS ) + LROT_FUNCENTRY( getFieldInfo, luaGetFieldInfo ) + LROT_FUNCENTRY( getSourceInfo, luaGetFieldInfo ) + LROT_FUNCENTRY( getFlightMode, luaGetFlightMode ) + LROT_FUNCENTRY( playFile, luaPlayFile ) + LROT_FUNCENTRY( playNumber, luaPlayNumber ) + LROT_FUNCENTRY( playDuration, luaPlayDuration ) + LROT_FUNCENTRY( playTone, luaPlayTone ) + LROT_FUNCENTRY( playHaptic, luaPlayHaptic ) + LROT_FUNCENTRY( flushAudio, luaFlushAudio ) #if defined(ENABLE_LUA_POPUP_INPUT) - { "popupInput", luaPopupInput }, + LROT_FUNCENTRY( popupInput, luaPopupInput ) #endif - { "popupWarning", luaPopupWarning }, - { "popupConfirmation", luaPopupConfirmation }, - { "defaultStick", luaDefaultStick }, - { "defaultChannel", luaDefaultChannel }, - { "getRSSI", luaGetRSSI }, - { "killEvents", luaKillEvents }, - { "dir", luaDir }, - { "fstat", luaFstat }, - { "chdir", luaChdir }, - { "loadScript", luaLoadScript }, - { "getUsage", luaGetUsage }, - { "getAvailableMemory", luaGetAvailableMemory }, - { "resetGlobalTimer", luaResetGlobalTimer }, + LROT_FUNCENTRY( popupWarning, luaPopupWarning ) + LROT_FUNCENTRY( popupConfirmation, luaPopupConfirmation ) + LROT_FUNCENTRY( defaultStick, luaDefaultStick ) + LROT_FUNCENTRY( defaultChannel, luaDefaultChannel ) + LROT_FUNCENTRY( getRSSI, luaGetRSSI ) + LROT_FUNCENTRY( killEvents, luaKillEvents ) + LROT_FUNCENTRY( chdir, luaChdir ) + LROT_FUNCENTRY( loadScript, luaLoadScript ) + LROT_FUNCENTRY( getUsage, luaGetUsage ) + LROT_FUNCENTRY( getAvailableMemory, luaGetAvailableMemory ) + LROT_FUNCENTRY( resetGlobalTimer, luaResetGlobalTimer ) #if LCD_DEPTH > 1 && !defined(COLORLCD) - { "GREY", luaGrey }, + LROT_FUNCENTRY( GREY, luaGrey ) #endif #if defined(PXX2) - { "accessTelemetryPush", luaAccessTelemetryPush }, + LROT_FUNCENTRY( accessTelemetryPush, luaAccessTelemetryPush ) #endif - { "sportTelemetryPop", luaSportTelemetryPop }, - { "sportTelemetryPush", luaSportTelemetryPush }, - { "setTelemetryValue", luaSetTelemetryValue }, + LROT_FUNCENTRY( sportTelemetryPop, luaSportTelemetryPop ) + LROT_FUNCENTRY( sportTelemetryPush, luaSportTelemetryPush ) + LROT_FUNCENTRY( setTelemetryValue, luaSetTelemetryValue ) #if defined(CROSSFIRE) - { "crossfireTelemetryPop", luaCrossfireTelemetryPop }, - { "crossfireTelemetryPush", luaCrossfireTelemetryPush }, + LROT_FUNCENTRY( crossfireTelemetryPop, luaCrossfireTelemetryPop ) + LROT_FUNCENTRY( crossfireTelemetryPush, luaCrossfireTelemetryPush ) #endif #if defined(GHOST) - { "ghostTelemetryPop", luaGhostTelemetryPop }, - { "ghostTelemetryPush", luaGhostTelemetryPush }, + LROT_FUNCENTRY( ghostTelemetryPop, luaGhostTelemetryPop ) + LROT_FUNCENTRY( ghostTelemetryPush, luaGhostTelemetryPush ) #endif #if defined(MULTIMODULE) - { "multiBuffer", luaMultiBuffer }, + LROT_FUNCENTRY( multiBuffer, luaMultiBuffer ) #endif - { "setSerialBaudrate", luaSetSerialBaudrate }, - { "serialWrite", luaSerialWrite }, - { "serialRead", luaSerialRead }, + LROT_FUNCENTRY( setSerialBaudrate, luaSetSerialBaudrate ) + LROT_FUNCENTRY( serialWrite, luaSerialWrite ) + LROT_FUNCENTRY( serialRead, luaSerialRead ) #if defined(COLORLCD) - { "setShmVar", luaSetShmVar }, - { "getShmVar", luaGetShmVar }, + LROT_FUNCENTRY( setShmVar, luaSetShmVar ) + LROT_FUNCENTRY( getShmVar, luaGetShmVar ) #endif - { "setStickySwitch", luaSetStickySwitch }, - { "getLogicalSwitchValue", luaGetLogicalSwitchValue }, - { "getSwitchIndex", luaGetSwitchIndex }, - { "getSwitchName", luaGetSwitchName }, - { "getSwitchValue", luaGetSwitchValue }, - { "switches", luaSwitches }, - { "getSourceIndex", luaGetSourceIndex }, - { "getSourceName", luaGetSourceName }, - { "sources", luaSources }, - { nullptr, nullptr } /* sentinel */ -}; - -const luaR_value_entry opentxConstants[] = { - { "FULLSCALE", RESX }, + LROT_FUNCENTRY( setStickySwitch, luaSetStickySwitch ) + LROT_FUNCENTRY( getLogicalSwitchValue, luaGetLogicalSwitchValue ) + LROT_FUNCENTRY( getSwitchIndex, luaGetSwitchIndex ) + LROT_FUNCENTRY( getSwitchName, luaGetSwitchName ) + LROT_FUNCENTRY( getSwitchValue, luaGetSwitchValue ) + LROT_FUNCENTRY( switches, luaSwitches ) + LROT_FUNCENTRY( getSourceIndex, luaGetSourceIndex ) + LROT_FUNCENTRY( getSourceName, luaGetSourceName ) + LROT_FUNCENTRY( sources, luaSources ) +LROT_END(etxlib, NULL, 0) + +LROT_BEGIN(etxcst, NULL, 0) + // Constants + LROT_NUMENTRY( FULLSCALE, RESX ) #if defined(COLORLCD) - { "XXLSIZE", FONT(XXL) }, - { "DBLSIZE", FONT(XL) }, - { "MIDSIZE", FONT(L) }, - { "SMLSIZE", FONT(XS) }, - { "TINSIZE", FONT(XXS) }, - { "BLINK", BLINK }, - { "INVERS", INVERS }, + LROT_NUMENTRY( XXLSIZE, FONT(XXL) ) + LROT_NUMENTRY( DBLSIZE, FONT(XL) ) + LROT_NUMENTRY( MIDSIZE, FONT(L) ) + LROT_NUMENTRY( SMLSIZE, FONT(XS) ) + LROT_NUMENTRY( TINSIZE, FONT(XXS) ) + LROT_NUMENTRY( BLINK, BLINK ) + LROT_NUMENTRY( INVERS, INVERS ) #else - { "XXLSIZE", XXLSIZE }, - { "DBLSIZE", DBLSIZE }, - { "MIDSIZE", MIDSIZE }, - { "SMLSIZE", SMLSIZE }, - { "BLINK", BLINK }, - { "INVERS", INVERS }, + LROT_NUMENTRY( XXLSIZE, XXLSIZE ) + LROT_NUMENTRY( DBLSIZE, DBLSIZE ) + LROT_NUMENTRY( MIDSIZE, MIDSIZE ) + LROT_NUMENTRY( SMLSIZE, SMLSIZE ) + LROT_NUMENTRY( BLINK, BLINK ) + LROT_NUMENTRY( INVERS, INVERS ) #endif #if defined(COLORLCD) - { "BOLD", FONT(BOLD) }, - { "VCENTER", VCENTERED }, + LROT_NUMENTRY( BOLD, FONT(BOLD) ) + LROT_NUMENTRY( VCENTER, VCENTERED ) #else - { "BOLD", BOLD }, + LROT_NUMENTRY( BOLD, BOLD ) #endif - { "RIGHT", RIGHT }, - { "LEFT", LEFT }, - { "CENTER", CENTERED }, - { "PREC1", PREC1 }, - { "PREC2", PREC2 }, - { "VALUE", INPUT_TYPE_VALUE }, - { "SOURCE", INPUT_TYPE_SOURCE }, - { "REPLACE", MLTPX_REPL }, - { "MIXSRC_MAX", MIXSRC_MAX }, - { "MIXSRC_FIRST_INPUT", MIXSRC_FIRST_INPUT }, - { "MIXSRC_Rud", MIXSRC_FIRST_STICK }, - { "MIXSRC_Ele", MIXSRC_FIRST_STICK + 1 }, - { "MIXSRC_Thr", MIXSRC_FIRST_STICK + 2 }, - { "MIXSRC_Ail", MIXSRC_FIRST_STICK + 3 }, + LROT_NUMENTRY( RIGHT, RIGHT ) + LROT_NUMENTRY( LEFT, LEFT ) + LROT_NUMENTRY( CENTER, CENTERED ) + LROT_NUMENTRY( PREC1, PREC1 ) + LROT_NUMENTRY( PREC2, PREC2 ) + LROT_NUMENTRY( VALUE, INPUT_TYPE_VALUE ) + LROT_NUMENTRY( SOURCE, INPUT_TYPE_SOURCE ) + LROT_NUMENTRY( REPLACE, MLTPX_REPL ) + LROT_NUMENTRY( MIXSRC_MAX, MIXSRC_MAX ) + LROT_NUMENTRY( MIXSRC_FIRST_INPUT, MIXSRC_FIRST_INPUT ) +// TODO: should be dynamic... + LROT_NUMENTRY( MIXSRC_Rud, MIXSRC_FIRST_STICK ) + LROT_NUMENTRY( MIXSRC_Ele, MIXSRC_FIRST_STICK + 1 ) + LROT_NUMENTRY( MIXSRC_Thr, MIXSRC_FIRST_STICK + 2 ) + LROT_NUMENTRY( MIXSRC_Ail, MIXSRC_FIRST_STICK + 3 ) // TODO: LUA switch names // { "MIXSRC_SA", MIXSRC_SA }, // { "MIXSRC_SB", MIXSRC_SB }, @@ -2798,369 +2800,367 @@ const luaR_value_entry opentxConstants[] = { // #if defined(HARDWARE_SWITCH_H) // { "MIXSRC_SH", MIXSRC_SH }, // #endif - { "MIXSRC_CH1", MIXSRC_FIRST_CH }, - { "SWSRC_LAST", SWSRC_LAST_LOGICAL_SWITCH }, - { "SWITCH_COUNT", SWSRC_COUNT }, - { "MAX_SENSORS", MAX_TELEMETRY_SENSORS }, - - { "MAX_OUTPUT_CHANNELS", MAX_OUTPUT_CHANNELS }, - { "LIMIT_EXT_PERCENT", LIMIT_EXT_PERCENT }, - { "LIMIT_STD_PERCENT", LIMIT_STD_PERCENT }, - - { "LS_FUNC_NONE", LS_FUNC_NONE }, - { "LS_FUNC_VEQUAL", LS_FUNC_VEQUAL }, - { "LS_FUNC_VALMOSTEQUAL", LS_FUNC_VALMOSTEQUAL }, - { "LS_FUNC_VPOS", LS_FUNC_VPOS }, - { "LS_FUNC_VNEG", LS_FUNC_VNEG }, - { "LS_FUNC_RANGE", LS_FUNC_RANGE }, - { "LS_FUNC_APOS", LS_FUNC_APOS }, - { "LS_FUNC_ANEG", LS_FUNC_ANEG }, - { "LS_FUNC_AND", LS_FUNC_AND }, - { "LS_FUNC_OR", LS_FUNC_OR }, - { "LS_FUNC_XOR", LS_FUNC_XOR }, - { "LS_FUNC_EDGE", LS_FUNC_EDGE }, - { "LS_FUNC_EQUAL", LS_FUNC_EQUAL }, - { "LS_FUNC_GREATER", LS_FUNC_GREATER }, - { "LS_FUNC_LESS", LS_FUNC_LESS }, - { "LS_FUNC_DIFFEGREATER", LS_FUNC_DIFFEGREATER }, - { "LS_FUNC_ADIFFEGREATER", LS_FUNC_ADIFFEGREATER }, - { "LS_FUNC_TIMER", LS_FUNC_TIMER }, - { "LS_FUNC_STICKY", LS_FUNC_STICKY }, - - { "FUNC_OVERRIDE_CHANNEL", FUNC_OVERRIDE_CHANNEL }, - { "FUNC_TRAINER", FUNC_TRAINER }, - { "FUNC_INSTANT_TRIM", FUNC_INSTANT_TRIM }, - { "FUNC_RESET", FUNC_RESET }, - { "FUNC_SET_TIMER", FUNC_SET_TIMER }, - { "FUNC_ADJUST_GVAR", FUNC_ADJUST_GVAR }, - { "FUNC_VOLUME", FUNC_VOLUME }, - { "FUNC_SET_FAILSAFE", FUNC_SET_FAILSAFE }, - { "FUNC_RANGECHECK", FUNC_RANGECHECK }, - { "FUNC_BIND", FUNC_BIND }, - { "FUNC_PLAY_SOUND", FUNC_PLAY_SOUND }, - { "FUNC_PLAY_TRACK", FUNC_PLAY_TRACK }, - { "FUNC_PLAY_VALUE", FUNC_PLAY_VALUE }, - { "FUNC_PLAY_SCRIPT", FUNC_PLAY_SCRIPT }, - { "FUNC_BACKGND_MUSIC", FUNC_BACKGND_MUSIC }, - { "FUNC_BACKGND_MUSIC_PAUSE", FUNC_BACKGND_MUSIC_PAUSE }, - { "FUNC_VARIO", FUNC_VARIO }, - { "FUNC_HAPTIC", FUNC_HAPTIC }, - { "FUNC_LOGS", FUNC_LOGS }, - { "FUNC_BACKLIGHT", FUNC_BACKLIGHT }, - { "FUNC_SCREENSHOT", FUNC_SCREENSHOT }, - { "FUNC_RACING_MODE", FUNC_RACING_MODE }, + LROT_NUMENTRY( MIXSRC_CH1, MIXSRC_FIRST_CH ) + LROT_NUMENTRY( SWSRC_LAST, SWSRC_LAST_LOGICAL_SWITCH ) + LROT_NUMENTRY( SWITCH_COUNT, SWSRC_COUNT ) + LROT_NUMENTRY( MAX_SENSORS, MAX_TELEMETRY_SENSORS ) + + LROT_NUMENTRY( MAX_OUTPUT_CHANNELS, MAX_OUTPUT_CHANNELS ) + LROT_NUMENTRY( LIMIT_EXT_PERCENT, LIMIT_EXT_PERCENT ) + LROT_NUMENTRY( LIMIT_STD_PERCENT, LIMIT_STD_PERCENT ) + + LROT_NUMENTRY( LS_FUNC_NONE, LS_FUNC_NONE ) + LROT_NUMENTRY( LS_FUNC_VEQUAL, LS_FUNC_VEQUAL ) + LROT_NUMENTRY( LS_FUNC_VALMOSTEQUAL, LS_FUNC_VALMOSTEQUAL ) + LROT_NUMENTRY( LS_FUNC_VPOS, LS_FUNC_VPOS ) + LROT_NUMENTRY( LS_FUNC_VNEG, LS_FUNC_VNEG ) + LROT_NUMENTRY( LS_FUNC_RANGE, LS_FUNC_RANGE ) + LROT_NUMENTRY( LS_FUNC_APOS, LS_FUNC_APOS ) + LROT_NUMENTRY( LS_FUNC_ANEG, LS_FUNC_ANEG ) + LROT_NUMENTRY( LS_FUNC_AND, LS_FUNC_AND ) + LROT_NUMENTRY( LS_FUNC_OR, LS_FUNC_OR ) + LROT_NUMENTRY( LS_FUNC_XOR, LS_FUNC_XOR ) + LROT_NUMENTRY( LS_FUNC_EDGE, LS_FUNC_EDGE ) + LROT_NUMENTRY( LS_FUNC_EQUAL, LS_FUNC_EQUAL ) + LROT_NUMENTRY( LS_FUNC_GREATER, LS_FUNC_GREATER ) + LROT_NUMENTRY( LS_FUNC_LESS, LS_FUNC_LESS ) + LROT_NUMENTRY( LS_FUNC_DIFFEGREATER, LS_FUNC_DIFFEGREATER ) + LROT_NUMENTRY( LS_FUNC_ADIFFEGREATER, LS_FUNC_ADIFFEGREATER ) + LROT_NUMENTRY( LS_FUNC_TIMER, LS_FUNC_TIMER ) + LROT_NUMENTRY( LS_FUNC_STICKY, LS_FUNC_STICKY ) + + LROT_NUMENTRY( FUNC_OVERRIDE_CHANNEL, FUNC_OVERRIDE_CHANNEL ) + LROT_NUMENTRY( FUNC_TRAINER, FUNC_TRAINER ) + LROT_NUMENTRY( FUNC_INSTANT_TRIM, FUNC_INSTANT_TRIM ) + LROT_NUMENTRY( FUNC_RESET, FUNC_RESET ) + LROT_NUMENTRY( FUNC_SET_TIMER, FUNC_SET_TIMER ) + LROT_NUMENTRY( FUNC_ADJUST_GVAR, FUNC_ADJUST_GVAR ) + LROT_NUMENTRY( FUNC_VOLUME, FUNC_VOLUME ) + LROT_NUMENTRY( FUNC_SET_FAILSAFE, FUNC_SET_FAILSAFE ) + LROT_NUMENTRY( FUNC_RANGECHECK, FUNC_RANGECHECK ) + LROT_NUMENTRY( FUNC_BIND, FUNC_BIND ) + LROT_NUMENTRY( FUNC_PLAY_SOUND, FUNC_PLAY_SOUND ) + LROT_NUMENTRY( FUNC_PLAY_TRACK, FUNC_PLAY_TRACK ) + LROT_NUMENTRY( FUNC_PLAY_VALUE, FUNC_PLAY_VALUE ) + LROT_NUMENTRY( FUNC_PLAY_SCRIPT, FUNC_PLAY_SCRIPT ) + LROT_NUMENTRY( FUNC_BACKGND_MUSIC, FUNC_BACKGND_MUSIC ) + LROT_NUMENTRY( FUNC_BACKGND_MUSIC_PAUSE, FUNC_BACKGND_MUSIC_PAUSE ) + LROT_NUMENTRY( FUNC_VARIO, FUNC_VARIO ) + LROT_NUMENTRY( FUNC_HAPTIC, FUNC_HAPTIC ) + LROT_NUMENTRY( FUNC_LOGS, FUNC_LOGS ) + LROT_NUMENTRY( FUNC_BACKLIGHT, FUNC_BACKLIGHT ) + LROT_NUMENTRY( FUNC_SCREENSHOT, FUNC_SCREENSHOT ) + LROT_NUMENTRY( FUNC_RACING_MODE, FUNC_RACING_MODE ) #if defined(COLORLCD) - { "FUNC_DISABLE_TOUCH", FUNC_DISABLE_TOUCH }, - { "FUNC_SET_SCREEN", FUNC_SET_SCREEN }, + LROT_NUMENTRY( FUNC_DISABLE_TOUCH, FUNC_DISABLE_TOUCH ) + LROT_NUMENTRY( FUNC_SET_SCREEN, FUNC_SET_SCREEN ) - { "SHADOWED", SHADOWED }, - { "COLOR", ZoneOption::Color }, - { "BOOL", ZoneOption::Bool }, - { "STRING", ZoneOption::String }, - { "TIMER", ZoneOption::Timer }, - { "TEXT_SIZE", ZoneOption::TextSize }, - { "MENU_HEADER_HEIGHT", COLOR2FLAGS(MENU_HEADER_HEIGHT) }, + LROT_NUMENTRY( SHADOWED, SHADOWED ) + LROT_NUMENTRY( COLOR, ZoneOption::Color ) + LROT_NUMENTRY( BOOL, ZoneOption::Bool ) + LROT_NUMENTRY( STRING, ZoneOption::String ) + LROT_NUMENTRY( TIMER, ZoneOption::Timer ) + LROT_NUMENTRY( TEXT_SIZE, ZoneOption::TextSize ) + LROT_NUMENTRY( MENU_HEADER_HEIGHT, COLOR2FLAGS(MENU_HEADER_HEIGHT) ) // Colors gui/colorlcd/colors.h - { "COLOR_THEME_PRIMARY1", COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) }, - { "COLOR_THEME_PRIMARY2", COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) }, - { "COLOR_THEME_PRIMARY3", COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) }, - { "COLOR_THEME_SECONDARY1", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "COLOR_THEME_SECONDARY2", COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) }, - { "COLOR_THEME_SECONDARY3", COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) }, - { "COLOR_THEME_FOCUS", COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) }, - { "COLOR_THEME_EDIT", COLOR2FLAGS(COLOR_THEME_EDIT_INDEX) }, - { "COLOR_THEME_ACTIVE", COLOR2FLAGS(COLOR_THEME_ACTIVE_INDEX) }, - { "COLOR_THEME_WARNING", COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) }, - { "COLOR_THEME_DISABLED", COLOR2FLAGS(COLOR_THEME_DISABLED_INDEX) }, - { "CUSTOM_COLOR", COLOR2FLAGS(CUSTOM_COLOR_INDEX) }, + LROT_NUMENTRY( COLOR_THEME_PRIMARY1, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_PRIMARY2, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_PRIMARY3, COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_SECONDARY1, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_SECONDARY2, COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_SECONDARY3, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_FOCUS, COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_EDIT, COLOR2FLAGS(COLOR_THEME_EDIT_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_ACTIVE, COLOR2FLAGS(COLOR_THEME_ACTIVE_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_WARNING, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) ) + LROT_NUMENTRY( COLOR_THEME_DISABLED, COLOR2FLAGS(COLOR_THEME_DISABLED_INDEX) ) + LROT_NUMENTRY( CUSTOM_COLOR, COLOR2FLAGS(CUSTOM_COLOR_INDEX) ) // Old style theme color constants - { "ALARM_COLOR", COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) }, - { "BARGRAPH_BGCOLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) }, - { "BARGRAPH1_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "BARGRAPH2_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) }, - { "CURVE_AXIS_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) }, - { "CURVE_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "CURVE_CURSOR_COLOR", COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) }, - { "HEADER_BGCOLOR", COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) }, - { "HEADER_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "HEADER_CURRENT_BGCOLOR", COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) }, - { "HEADER_ICON_BGCOLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "LINE_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) }, - { "MAINVIEW_GRAPHICS_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "MAINVIEW_PANES_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) }, - { "MENU_TITLE_BGCOLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "MENU_TITLE_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) }, - { "MENU_TITLE_DISABLE_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) }, - { "OVERLAY_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) }, - { "SCROLLBOX_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) }, - { "TEXT_BGCOLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) }, - { "TEXT_COLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "TEXT_DISABLE_COLOR", COLOR2FLAGS(COLOR_THEME_DISABLED_INDEX) }, - { "TEXT_INVERTED_BGCOLOR", COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) }, - { "TEXT_INVERTED_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) }, - { "TITLE_BGCOLOR", COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) }, - { "TRIM_BGCOLOR", COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) }, - { "TRIM_SHADOW_COLOR", COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) }, - { "WARNING_COLOR", COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) }, + LROT_NUMENTRY( ALARM_COLOR, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) ) + LROT_NUMENTRY( BARGRAPH_BGCOLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) ) + LROT_NUMENTRY( BARGRAPH1_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( BARGRAPH2_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) ) + LROT_NUMENTRY( CURVE_AXIS_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY2_INDEX) ) + LROT_NUMENTRY( CURVE_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( CURVE_CURSOR_COLOR, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) ) + LROT_NUMENTRY( HEADER_BGCOLOR, COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) ) + LROT_NUMENTRY( HEADER_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( HEADER_CURRENT_BGCOLOR, COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) ) + LROT_NUMENTRY( HEADER_ICON_BGCOLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( LINE_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) ) + LROT_NUMENTRY( MAINVIEW_GRAPHICS_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( MAINVIEW_PANES_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) ) + LROT_NUMENTRY( MENU_TITLE_BGCOLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( MENU_TITLE_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) ) + LROT_NUMENTRY( MENU_TITLE_DISABLE_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY3_INDEX) ) + LROT_NUMENTRY( OVERLAY_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) ) + LROT_NUMENTRY( SCROLLBOX_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) ) + LROT_NUMENTRY( TEXT_BGCOLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX) ) + LROT_NUMENTRY( TEXT_COLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( TEXT_DISABLE_COLOR, COLOR2FLAGS(COLOR_THEME_DISABLED_INDEX) ) + LROT_NUMENTRY( TEXT_INVERTED_BGCOLOR, COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) ) + LROT_NUMENTRY( TEXT_INVERTED_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX) ) + LROT_NUMENTRY( TITLE_BGCOLOR, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX) ) + LROT_NUMENTRY( TRIM_BGCOLOR, COLOR2FLAGS(COLOR_THEME_FOCUS_INDEX) ) + LROT_NUMENTRY( TRIM_SHADOW_COLOR, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX) ) + LROT_NUMENTRY( WARNING_COLOR, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX) ) // Literal colors - { "BLACK", RGB2FLAGS(0x00, 0x00, 0x00) }, - { "WHITE", RGB2FLAGS(0xFF, 0xFF, 0xFF) }, - { "LIGHTWHITE", RGB2FLAGS(0xEA, 0xEA, 0xEA) }, - { "YELLOW", RGB2FLAGS(0xFF, 0xFF, 0x00) }, - { "BLUE", RGB2FLAGS(0x00, 0x00, 0xFF) }, - { "DARKBLUE", RGB2FLAGS(0x00, 0x00, 0xA0) }, - { "GREY", RGB2FLAGS(0x60, 0x60, 0x60) }, - { "DARKGREY", RGB2FLAGS(0x40, 0x40, 0x40) }, - { "LIGHTGREY", RGB2FLAGS(0xC0, 0xC0, 0xC0) }, - { "RED", RGB2FLAGS(0xFF, 0x00, 0x00) }, - { "DARKRED", RGB2FLAGS(0xA0, 0x00, 0x00) }, - { "GREEN", RGB2FLAGS(0x00, 0xFF, 0x00) }, - { "DARKGREEN", RGB2FLAGS(0x00, 0xA0, 0x00) }, - { "LIGHTBROWN", RGB2FLAGS(0x9C, 0x6D, 0x20) }, - { "DARKBROWN", RGB2FLAGS(0x6A, 0x48, 0x10) }, - { "BRIGHTGREEN", RGB2FLAGS(0x00, 0xB4, 0x3C) }, - { "ORANGE", RGB2FLAGS(0xE5, 0x64, 0x1E) }, + LROT_NUMENTRY( BLACK, RGB2FLAGS(0x00, 0x00, 0x00) ) + LROT_NUMENTRY( WHITE, RGB2FLAGS(0xFF, 0xFF, 0xFF) ) + LROT_NUMENTRY( LIGHTWHITE, RGB2FLAGS(0xEA, 0xEA, 0xEA) ) + LROT_NUMENTRY( YELLOW, RGB2FLAGS(0xFF, 0xFF, 0x00) ) + LROT_NUMENTRY( BLUE, RGB2FLAGS(0x00, 0x00, 0xFF) ) + LROT_NUMENTRY( DARKBLUE, RGB2FLAGS(0x00, 0x00, 0xA0) ) + LROT_NUMENTRY( GREY, RGB2FLAGS(0x60, 0x60, 0x60) ) + LROT_NUMENTRY( DARKGREY, RGB2FLAGS(0x40, 0x40, 0x40) ) + LROT_NUMENTRY( LIGHTGREY, RGB2FLAGS(0xC0, 0xC0, 0xC0) ) + LROT_NUMENTRY( RED, RGB2FLAGS(0xFF, 0x00, 0x00) ) + LROT_NUMENTRY( DARKRED, RGB2FLAGS(0xA0, 0x00, 0x00) ) + LROT_NUMENTRY( GREEN, RGB2FLAGS(0x00, 0xFF, 0x00) ) + LROT_NUMENTRY( DARKGREEN, RGB2FLAGS(0x00, 0xA0, 0x00) ) + LROT_NUMENTRY( LIGHTBROWN, RGB2FLAGS(0x9C, 0x6D, 0x20) ) + LROT_NUMENTRY( DARKBROWN, RGB2FLAGS(0x6A, 0x48, 0x10) ) + LROT_NUMENTRY( BRIGHTGREEN, RGB2FLAGS(0x00, 0xB4, 0x3C) ) + LROT_NUMENTRY( ORANGE, RGB2FLAGS(0xE5, 0x64, 0x1E) ) #else - { "FIXEDWIDTH", FIXEDWIDTH }, + LROT_NUMENTRY( FIXEDWIDTH, FIXEDWIDTH ) #endif // Virtual events #if defined(ROTARY_ENCODER_NAVIGATION) - { "EVT_VIRTUAL_PREV", EVT_ROTARY_LEFT }, - { "EVT_VIRTUAL_NEXT", EVT_ROTARY_RIGHT }, - { "EVT_VIRTUAL_DEC", EVT_ROTARY_LEFT }, - { "EVT_VIRTUAL_INC", EVT_ROTARY_RIGHT }, - { "ROTENC_LOWSPEED", ROTENC_LOWSPEED }, - { "ROTENC_MIDSPEED", ROTENC_MIDSPEED }, - { "ROTENC_HIGHSPEED", ROTENC_HIGHSPEED }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_ROTARY_LEFT ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_ROTARY_RIGHT ) + LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_ROTARY_LEFT ) + LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_ROTARY_RIGHT ) + LROT_NUMENTRY( ROTENC_LOWSPEED, ROTENC_LOWSPEED ) + LROT_NUMENTRY( ROTENC_MIDSPEED, ROTENC_MIDSPEED ) + LROT_NUMENTRY( ROTENC_HIGHSPEED, ROTENC_HIGHSPEED ) #elif defined(PCBX9D) || defined(PCBX9DP) || defined(RADIO_T8) || defined(RADIO_COMMANDO8)// key reverted between field nav and value change - { "EVT_VIRTUAL_PREV", EVT_KEY_FIRST(KEY_PLUS) }, - { "EVT_VIRTUAL_PREV_REPT", EVT_KEY_REPT(KEY_PLUS) }, - { "EVT_VIRTUAL_NEXT", EVT_KEY_FIRST(KEY_MINUS) }, - { "EVT_VIRTUAL_NEXT_REPT", EVT_KEY_REPT(KEY_MINUS) }, - { "EVT_VIRTUAL_DEC", EVT_KEY_FIRST(KEY_MINUS) }, - { "EVT_VIRTUAL_DEC_REPT", EVT_KEY_REPT(KEY_MINUS) }, - { "EVT_VIRTUAL_INC", EVT_KEY_FIRST(KEY_PLUS) }, - { "EVT_VIRTUAL_INC_REPT", EVT_KEY_REPT(KEY_PLUS) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_PLUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_PLUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_MINUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_MINUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_MINUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_MINUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_PLUS) ) + LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_PLUS) ) #else - { "EVT_VIRTUAL_PREV", EVT_KEY_FIRST(KEY_UP) }, - { "EVT_VIRTUAL_PREV_REPT", EVT_KEY_REPT(KEY_UP) }, - { "EVT_VIRTUAL_NEXT", EVT_KEY_FIRST(KEY_DOWN) }, - { "EVT_VIRTUAL_NEXT_REPT", EVT_KEY_REPT(KEY_DOWN) }, - { "EVT_VIRTUAL_DEC", EVT_KEY_FIRST(KEY_DOWN) }, - { "EVT_VIRTUAL_DEC_REPT", EVT_KEY_REPT(KEY_DOWN) }, - { "EVT_VIRTUAL_INC", EVT_KEY_FIRST(KEY_UP) }, - { "EVT_VIRTUAL_INC_REPT", EVT_KEY_REPT(KEY_UP) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_UP) ) + LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_UP) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_DOWN) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_DOWN) ) + LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_DOWN) ) + LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_DOWN) ) + LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_UP) ) + LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_UP) ) #endif #if defined(NAVIGATION_9X) - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_LONG(KEY_LEFT) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_LEFT) }, - { "EVT_VIRTUAL_MENU", EVT_KEY_BREAK(KEY_RIGHT) }, - { "EVT_VIRTUAL_MENU_LONG", EVT_KEY_LONG(KEY_RIGHT) }, - { "EVT_VIRTUAL_ENTER", EVT_KEY_BREAK(KEY_ENTER) }, - { "EVT_VIRTUAL_ENTER_LONG", EVT_KEY_LONG(KEY_ENTER) }, - { "EVT_VIRTUAL_EXIT", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_LEFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_RIGHT) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_RIGHT) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) ) #elif defined(NAVIGATION_XLITE) - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_LONG(KEY_LEFT) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_LONG(KEY_RIGHT) }, - { "EVT_VIRTUAL_MENU", EVT_KEY_BREAK(KEY_SHIFT) }, - { "EVT_VIRTUAL_MENU_LONG", EVT_KEY_LONG(KEY_SHIFT) }, - { "EVT_VIRTUAL_ENTER", EVT_KEY_BREAK(KEY_ENTER) }, - { "EVT_VIRTUAL_ENTER_LONG", EVT_KEY_LONG(KEY_ENTER) }, - { "EVT_VIRTUAL_EXIT", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_LONG(KEY_RIGHT) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_SHIFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_SHIFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) ) #elif defined(NAVIGATION_X7) || defined(NAVIGATION_X9D) #if defined(RADIO_TX12) || defined(RADIO_TX12MK2) || defined(RADIO_BOXER) || defined(RADIO_ZORRO) || defined(RADIO_T8) || defined(RADIO_COMMANDO8) - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_BREAK(KEY_PAGEUP) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PAGEDN) }, - { "EVT_VIRTUAL_MENU", EVT_KEY_BREAK(KEY_MODEL) }, - { "EVT_VIRTUAL_MENU_LONG", EVT_KEY_LONG(KEY_MODEL) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_PAGEUP) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MODEL) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MODEL) ) #else - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_LONG(KEY_PAGE) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PAGE) }, - { "EVT_VIRTUAL_MENU", EVT_KEY_BREAK(KEY_MENU) }, - { "EVT_VIRTUAL_MENU_LONG", EVT_KEY_LONG(KEY_MENU) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PAGE) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGE) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MENU) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MENU) ) #endif - { "EVT_VIRTUAL_ENTER", EVT_KEY_BREAK(KEY_ENTER) }, - { "EVT_VIRTUAL_ENTER_LONG", EVT_KEY_LONG(KEY_ENTER) }, - { "EVT_VIRTUAL_EXIT", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) ) #elif defined(COLORLCD) #if defined(KEYS_GPIO_REG_PGUP) - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_BREAK(KEY_PGUP) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PGDN) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_PGUP) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PGDN) ) #elif defined(PCBNV14) - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_BREAK(KEY_LEFT) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_RIGHT) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_LEFT) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_RIGHT) ) #else - { "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_LONG(KEY_PGDN) }, - { "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PGDN) }, + LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PGDN) ) + LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PGDN) ) #endif - { "EVT_VIRTUAL_MENU", EVT_KEY_BREAK(KEY_MODEL) }, - { "EVT_VIRTUAL_MENU_LONG", EVT_KEY_LONG(KEY_MODEL) }, - { "EVT_VIRTUAL_ENTER", EVT_KEY_BREAK(KEY_ENTER) }, - { "EVT_VIRTUAL_ENTER_LONG", EVT_KEY_LONG(KEY_ENTER) }, - { "EVT_VIRTUAL_EXIT", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MODEL) ) + LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MODEL) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) ) + LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) ) #endif - { "EVT_EXIT_BREAK", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_EXIT_BREAK, EVT_KEY_BREAK(KEY_EXIT) ) #if defined(KEYS_GPIO_REG_ENTER) - KEY_EVENTS(ENTER, KEY_ENTER), + KEY_EVENTS(ENTER, KEY_ENTER) #endif #if defined(KEYS_GPIO_REG_MENU) - KEY_EVENTS(MENU, KEY_MENU), + KEY_EVENTS(MENU, KEY_MENU) #endif #if defined(KEYS_GPIO_REG_RIGHT) && defined(COLORLCD) - KEY_EVENTS(TELEM, KEY_TELEM), + KEY_EVENTS(TELEM, KEY_TELEM) #elif defined(KEYS_GPIO_REG_RIGHT) - KEY_EVENTS(RIGHT, KEY_RIGHT), + KEY_EVENTS(RIGHT, KEY_RIGHT) #endif #if defined(KEYS_GPIO_REG_UP) && defined(COLORLCD) - KEY_EVENTS(MODEL, KEY_MODEL), + KEY_EVENTS(MODEL, KEY_MODEL) #elif defined(KEYS_GPIO_REG_UP) - KEY_EVENTS(UP, KEY_UP), + KEY_EVENTS(UP, KEY_UP) #endif #if defined(KEYS_GPIO_REG_LEFT) && defined(COLORLCD) - KEY_EVENTS(SYS, KEY_RADIO), + KEY_EVENTS(SYS, KEY_RADIO) #elif defined(KEYS_GPIO_REG_LEFT) - KEY_EVENTS(LEFT, KEY_LEFT), + KEY_EVENTS(LEFT, KEY_LEFT) #endif #if defined(KEYS_GPIO_REG_DOWN) && defined(COLORLCD) - { "EVT_RTN_FIRST", EVT_KEY_BREAK(KEY_EXIT) }, + LROT_NUMENTRY( EVT_RTN_FIRST, EVT_KEY_BREAK(KEY_EXIT) ) #else - KEY_EVENTS(DOWN, KEY_DOWN), + KEY_EVENTS(DOWN, KEY_DOWN) #endif #if defined(KEYS_GPIO_REG_PGUP) - KEY_EVENTS(PAGEUP, KEY_PGUP), + KEY_EVENTS(PAGEUP, KEY_PGUP) #endif #if defined(KEYS_GPIO_REG_PGDN) - KEY_EVENTS(PAGEDN, KEY_PGDN), + KEY_EVENTS(PAGEDN, KEY_PGDN) #endif #if defined(KEYS_GPIO_REG_PAGE) - KEY_EVENTS(PAGE, KEY_PAGE), + KEY_EVENTS(PAGE, KEY_PAGE) #endif #if defined(KEYS_GPIO_REG_SHIFT) - KEY_EVENTS(SHIFT, KEY_SHIFT), + KEY_EVENTS(SHIFT, KEY_SHIFT) #endif #if defined(KEYS_GPIO_REG_PLUS) - KEY_EVENTS(PLUS, KEY_PLUS), + KEY_EVENTS(PLUS, KEY_PLUS) #endif #if defined(KEYS_GPIO_REG_MINUS) - KEY_EVENTS(MINUS, KEY_MINUS), + KEY_EVENTS(MINUS, KEY_MINUS) #endif #if defined(ROTARY_ENCODER_NAVIGATION) - KEY_EVENTS(ROT, KEY_ENTER), - { "EVT_ROT_LEFT", EVT_ROTARY_LEFT }, - { "EVT_ROT_RIGHT", EVT_ROTARY_RIGHT }, + KEY_EVENTS(ROT, KEY_ENTER) + LROT_NUMENTRY( EVT_ROT_LEFT, EVT_ROTARY_LEFT ) + LROT_NUMENTRY( EVT_ROT_RIGHT, EVT_ROTARY_RIGHT ) #endif #if defined(HARDWARE_TOUCH) - { "EVT_TOUCH_FIRST", EVT_TOUCH_FIRST }, - { "EVT_TOUCH_BREAK", EVT_TOUCH_BREAK }, - { "EVT_TOUCH_SLIDE", EVT_TOUCH_SLIDE }, - { "EVT_TOUCH_TAP", EVT_TOUCH_TAP }, + LROT_NUMENTRY( EVT_TOUCH_FIRST, EVT_TOUCH_FIRST ) + LROT_NUMENTRY( EVT_TOUCH_BREAK, EVT_TOUCH_BREAK ) + LROT_NUMENTRY( EVT_TOUCH_SLIDE, EVT_TOUCH_SLIDE ) + LROT_NUMENTRY( EVT_TOUCH_TAP, EVT_TOUCH_TAP ) #endif #if LCD_DEPTH > 1 && !defined(COLORLCD) - { "FILL_WHITE", FILL_WHITE }, - { "GREY_DEFAULT", GREY_DEFAULT }, + LROT_NUMENTRY( FILL_WHITE, FILL_WHITE ) + LROT_NUMENTRY( GREY_DEFAULT, GREY_DEFAULT ) #endif #if LCD_W <= 212 - { "FORCE", FORCE }, - { "ERASE", ERASE }, - { "ROUND", ROUND }, + LROT_NUMENTRY( FORCE, FORCE ) + LROT_NUMENTRY( ERASE, ERASE ) + LROT_NUMENTRY( ROUND, ROUND ) #endif - { "SOLID", SOLID }, - { "DOTTED", DOTTED }, - { "LCD_W", LCD_W }, - { "LCD_H", LCD_H }, - { "PLAY_NOW", PLAY_NOW }, - { "PLAY_BACKGROUND", PLAY_BACKGROUND }, - { "TIMEHOUR", TIMEHOUR }, - - {"UNIT_RAW", UNIT_RAW }, - {"UNIT_VOLTS", UNIT_VOLTS }, - {"UNIT_AMPS", UNIT_AMPS }, - {"UNIT_MILLIAMPS", UNIT_MILLIAMPS }, - {"UNIT_KTS", UNIT_KTS }, - {"UNIT_METERS_PER_SECOND", UNIT_METERS_PER_SECOND }, - {"UNIT_FEET_PER_SECOND", UNIT_FEET_PER_SECOND }, - {"UNIT_KMH", UNIT_KMH }, - {"UNIT_MPH", UNIT_MPH }, - {"UNIT_METERS", UNIT_METERS }, - {"UNIT_KM", UNIT_KM }, - {"UNIT_FEET", UNIT_FEET }, - {"UNIT_CELSIUS", UNIT_CELSIUS }, - {"UNIT_FAHRENHEIT", UNIT_FAHRENHEIT }, - {"UNIT_PERCENT", UNIT_PERCENT }, - {"UNIT_MAH", UNIT_MAH }, - {"UNIT_WATTS", UNIT_WATTS }, - {"UNIT_MILLIWATTS", UNIT_MILLIWATTS }, - {"UNIT_DB", UNIT_DB }, - {"UNIT_RPMS", UNIT_RPMS }, - {"UNIT_G", UNIT_G }, - {"UNIT_DEGREE", UNIT_DEGREE }, - {"UNIT_RADIANS", UNIT_RADIANS }, - {"UNIT_MILLILITERS", UNIT_MILLILITERS }, - {"UNIT_FLOZ", UNIT_FLOZ }, - {"UNIT_MILLILITERS_PER_MINUTE", UNIT_MILLILITERS_PER_MINUTE }, - {"UNIT_HERTZ", UNIT_HERTZ }, - {"UNIT_MS", UNIT_MS }, - {"UNIT_US", UNIT_US }, - {"UNIT_HOURS", UNIT_HOURS }, - {"UNIT_MINUTES", UNIT_MINUTES }, - {"UNIT_SECONDS", UNIT_SECONDS }, - {"UNIT_CELLS", UNIT_CELLS}, - {"UNIT_DATETIME", UNIT_DATETIME}, - {"UNIT_GPS", UNIT_GPS}, - {"UNIT_BITFIELD", UNIT_BITFIELD}, - {"UNIT_TEXT", UNIT_TEXT}, - - {"AM_RDO", AM_RDO}, - {"AM_HID", AM_HID}, - {"AM_SYS", AM_SYS}, - {"AM_DIR", AM_DIR}, - {"AM_ARC", AM_ARC}, - - { nullptr, 0 } /* sentinel */ -}; - -const luaR_string_entry edgetxStrings[] = { - { "CHAR_RIGHT", STR_CHAR_RIGHT }, - { "CHAR_LEFT", STR_CHAR_LEFT }, - { "CHAR_UP", STR_CHAR_UP }, - { "CHAR_DOWN", STR_CHAR_DOWN }, - { "CHAR_DELTA", STR_CHAR_DELTA }, - { "CHAR_STICK", STR_CHAR_STICK }, - { "CHAR_POT", STR_CHAR_POT }, - { "CHAR_SLIDER", STR_CHAR_SLIDER }, - { "CHAR_SWITCH", STR_CHAR_SWITCH }, - { "CHAR_TRIM", STR_CHAR_TRIM }, - { "CHAR_INPUT", STR_CHAR_INPUT }, - { "CHAR_FUNCTION", STR_CHAR_FUNCTION }, - { "CHAR_CYC", STR_CHAR_CYC }, - { "CHAR_TRAINER", STR_CHAR_TRAINER }, - { "CHAR_CHANNEL", STR_CHAR_CHANNEL }, - { "CHAR_TELEMETRY", STR_CHAR_TELEMETRY }, - { "CHAR_LUA", STR_CHAR_LUA }, - - { nullptr, "" } /* sentinel */ -}; + LROT_NUMENTRY( SOLID, SOLID ) + LROT_NUMENTRY( DOTTED, DOTTED ) + LROT_NUMENTRY( LCD_W, LCD_W ) + LROT_NUMENTRY( LCD_H, LCD_H ) + LROT_NUMENTRY( PLAY_NOW, PLAY_NOW ) + LROT_NUMENTRY( PLAY_BACKGROUND, PLAY_BACKGROUND ) + LROT_NUMENTRY( TIMEHOUR, TIMEHOUR ) + + LROT_NUMENTRY( UNIT_RAW, UNIT_RAW ) + LROT_NUMENTRY( UNIT_VOLTS, UNIT_VOLTS ) + LROT_NUMENTRY( UNIT_AMPS, UNIT_AMPS ) + LROT_NUMENTRY( UNIT_MILLIAMPS, UNIT_MILLIAMPS ) + LROT_NUMENTRY( UNIT_KTS, UNIT_KTS ) + LROT_NUMENTRY( UNIT_METERS_PER_SECOND, UNIT_METERS_PER_SECOND ) + LROT_NUMENTRY( UNIT_FEET_PER_SECOND, UNIT_FEET_PER_SECOND ) + LROT_NUMENTRY( UNIT_KMH, UNIT_KMH ) + LROT_NUMENTRY( UNIT_MPH, UNIT_MPH ) + LROT_NUMENTRY( UNIT_METERS, UNIT_METERS ) + LROT_NUMENTRY( UNIT_KM, UNIT_KM ) + LROT_NUMENTRY( UNIT_FEET, UNIT_FEET ) + LROT_NUMENTRY( UNIT_CELSIUS, UNIT_CELSIUS ) + LROT_NUMENTRY( UNIT_FAHRENHEIT, UNIT_FAHRENHEIT ) + LROT_NUMENTRY( UNIT_PERCENT, UNIT_PERCENT ) + LROT_NUMENTRY( UNIT_MAH, UNIT_MAH ) + LROT_NUMENTRY( UNIT_WATTS, UNIT_WATTS ) + LROT_NUMENTRY( UNIT_MILLIWATTS, UNIT_MILLIWATTS ) + LROT_NUMENTRY( UNIT_DB, UNIT_DB ) + LROT_NUMENTRY( UNIT_RPMS, UNIT_RPMS ) + LROT_NUMENTRY( UNIT_G, UNIT_G ) + LROT_NUMENTRY( UNIT_DEGREE, UNIT_DEGREE ) + LROT_NUMENTRY( UNIT_RADIANS, UNIT_RADIANS ) + LROT_NUMENTRY( UNIT_MILLILITERS, UNIT_MILLILITERS ) + LROT_NUMENTRY( UNIT_FLOZ, UNIT_FLOZ ) + LROT_NUMENTRY( UNIT_MILLILITERS_PER_MINUTE, UNIT_MILLILITERS_PER_MINUTE ) + LROT_NUMENTRY( UNIT_HERTZ, UNIT_HERTZ ) + LROT_NUMENTRY( UNIT_MS, UNIT_MS ) + LROT_NUMENTRY( UNIT_US, UNIT_US ) + LROT_NUMENTRY( UNIT_HOURS, UNIT_HOURS ) + LROT_NUMENTRY( UNIT_MINUTES, UNIT_MINUTES ) + LROT_NUMENTRY( UNIT_SECONDS, UNIT_SECONDS ) + LROT_NUMENTRY( UNIT_CELLS, UNIT_CELLS ) + LROT_NUMENTRY( UNIT_DATETIME, UNIT_DATETIME ) + LROT_NUMENTRY( UNIT_GPS, UNIT_GPS ) + LROT_NUMENTRY( UNIT_BITFIELD, UNIT_BITFIELD ) + LROT_NUMENTRY( UNIT_TEXT, UNIT_TEXT ) + + LROT_NUMENTRY( AM_RDO, AM_RDO ) + LROT_NUMENTRY( AM_HID, AM_HID ) + LROT_NUMENTRY( AM_SYS, AM_SYS ) + LROT_NUMENTRY( AM_DIR, AM_DIR ) + LROT_NUMENTRY( AM_ARC, AM_ARC ) +LROT_END(etxcst, NULL, 0) + +// LUA strings cannot be encoded statically, +// use light user data instead +LROT_BEGIN(etxstr, NULL, 0) + LROT_LUDENTRY( CHAR_RIGHT, STR_CHAR_RIGHT ) + LROT_LUDENTRY( CHAR_LEFT, STR_CHAR_LEFT ) + LROT_LUDENTRY( CHAR_UP, STR_CHAR_UP ) + LROT_LUDENTRY( CHAR_DOWN, STR_CHAR_DOWN ) + LROT_LUDENTRY( CHAR_DELTA, STR_CHAR_DELTA ) + LROT_LUDENTRY( CHAR_STICK, STR_CHAR_STICK ) + LROT_LUDENTRY( CHAR_POT, STR_CHAR_POT ) + LROT_LUDENTRY( CHAR_SLIDER, STR_CHAR_SLIDER ) + LROT_LUDENTRY( CHAR_SWITCH, STR_CHAR_SWITCH ) + LROT_LUDENTRY( CHAR_TRIM, STR_CHAR_TRIM ) + LROT_LUDENTRY( CHAR_INPUT, STR_CHAR_INPUT ) + LROT_LUDENTRY( CHAR_FUNCTION, STR_CHAR_FUNCTION ) + LROT_LUDENTRY( CHAR_CYC, STR_CHAR_CYC ) + LROT_LUDENTRY( CHAR_TRAINER, STR_CHAR_TRAINER ) + LROT_LUDENTRY( CHAR_CHANNEL, STR_CHAR_CHANNEL ) + LROT_LUDENTRY( CHAR_TELEMETRY, STR_CHAR_TELEMETRY ) + LROT_LUDENTRY( CHAR_LUA, STR_CHAR_LUA ) +LROT_END(etxstr, NULL, 0) diff --git a/radio/src/lua/api_lcd.cpp b/radio/src/lua/api_lcd.cpp deleted file mode 100644 index d1a1188772c..00000000000 --- a/radio/src/lua/api_lcd.cpp +++ /dev/null @@ -1,949 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * Based on code named - * opentx - https://github.com/opentx/opentx - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include -#include "opentx.h" -#include "lua_api.h" - -/*luadoc -@function lcd.refresh() - -Refresh the LCD screen - -@status current Introduced in 2.2.0 - -@notice This function only works in stand-alone and telemetry scripts. -*/ -static int luaLcdRefresh(lua_State *L) -{ - if (luaLcdAllowed) lcdRefresh(); - return 0; -} - -/*luadoc -@function lcd.clear([color]) - -Clear the LCD screen - -@param color (optional, only on color screens) - -@status current Introduced in 2.0.0, `color` parameter introduced in 2.2.0 RC12 - -@notice This function only works in stand-alone and telemetry scripts. -*/ -static int luaLcdClear(lua_State *L) -{ - if (luaLcdAllowed) { -#if defined(COLORLCD) - LcdFlags color = luaL_optunsigned(L, 1, COLOR_THEME_SECONDARY3); - lcd->clear(color); -#else - lcdClear(); -#endif - } - return 0; -} - -/*luadoc -@function lcd.resetBacklightTimeout() - -Reset the backlight timeout - -@status current Introduced in 2.3.6 -*/ -static int luaLcdResetBacklightTimeout(lua_State * L) -{ - if (!luaLcdAllowed) - return 0; - resetBacklightTimeout(); - return 0; -} - -/*luadoc -@function lcd.drawPoint(x, y) - -Draw a single pixel at (x,y) position - -@param x (positive number) x position - -@param y (positive number) y position - -@param flags (optional) lcdflags - -@notice Taranis has an LCD display width of 212 pixels and height of 64 pixels. -Position (0,0) is at top left. Y axis is negative, top line is 0, -bottom line is 63. Drawing on an existing black pixel produces white pixel (TODO check this!) - -@status current Introduced in 2.0.0 -*/ -static int luaLcdDrawPoint(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - LcdFlags att = luaL_optunsigned(L, 3, 0); - lcdDrawPoint(x, y, att); - return 0; -} - -/*luadoc -@function lcd.drawLine(x1, y1, x2, y2, pattern, flags) - -Draw a straight line on LCD - -@param x1,y1 (positive numbers) starting coordinate - -@param x2,y2 (positive numbers) end coordinate - -@param pattern SOLID or DOTTED - -@param flags lcdflags - -@notice If the start or the end of the line is outside the LCD dimensions, then the -whole line will not be drawn (starting from OpenTX 2.1.5) - -@status current Introduced in 2.0.0, flags introduced in 2.3.6 -*/ -static int luaLcdDrawLine(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - coord_t x1 = luaL_checkunsigned(L, 1); - coord_t y1 = luaL_checkunsigned(L, 2); - coord_t x2 = luaL_checkunsigned(L, 3); - coord_t y2 = luaL_checkunsigned(L, 4); - uint8_t pat = luaL_checkunsigned(L, 5); - LcdFlags flags = luaL_checkunsigned(L, 6); - - if (x1 > LCD_W || y1 > LCD_H || x2 > LCD_W || y2 > LCD_H) - return 0; - - if (pat == SOLID) { - if (x1 == x2) { - lcdDrawSolidVerticalLine(x1, y1 LUA_MEM_EXTRA_MAX) { - // already allocated more than max allowed, fail - TRACE("luaOpenBitmap: Error, using too much memory %u/%u", luaExtraMemoryUsage, LUA_MEM_EXTRA_MAX); - *b = 0; - } - else { - *b = BitmapBuffer::load(filename); - if (*b == NULL && G(L)->gcrunning) { - luaC_fullgc(L, 1); /* try to free some memory... */ - *b = BitmapBuffer::load(filename); /* try again */ - } - } - - if (*b) { - uint32_t size = (*b)->getDataSize(); - luaExtraMemoryUsage += size; - TRACE("luaOpenBitmap: %p (%u)", *b, size); - } - - luaL_getmetatable(L, LUA_BITMAPHANDLE); - lua_setmetatable(L, -2); - - return 1; -} - -static BitmapBuffer * checkBitmap(lua_State * L, int index) -{ - BitmapBuffer ** b = (BitmapBuffer **)luaL_checkudata(L, index, LUA_BITMAPHANDLE); - return *b; -} - -/*luadoc -@function Bitmap.getSize(name) - -Return width, height of a bitmap object - -@param bitmap (pointer) point to a bitmap previously opened with Bitmap.open() - -@retval multiple returns 2 values: - * (number) width in pixels - * (number) height in pixels - -@notice Only available on Horus - -@status current Introduced in 2.2.0 -*/ -static int luaGetBitmapSize(lua_State * L) -{ - const BitmapBuffer * b = checkBitmap(L, 1); - if (b) { - lua_pushinteger(L, b->width()); - lua_pushinteger(L, b->height()); - } - else { - lua_pushinteger(L, 0); - lua_pushinteger(L, 0); - } - return 2; -} - -static int luaDestroyBitmap(lua_State * L) -{ - BitmapBuffer * b = checkBitmap(L, 1); - if (b) { - uint32_t size = b->getDataSize(); - TRACE("luaDestroyBitmap: %p (%u)", b, size); - if (luaExtraMemoryUsage >= size) { - luaExtraMemoryUsage -= size; - } - else { - luaExtraMemoryUsage = 0; - } - delete b; - } - return 0; -} - -const luaL_Reg bitmapFuncs[] = { - { "open", luaOpenBitmap }, - { "getSize", luaGetBitmapSize }, - { "__gc", luaDestroyBitmap }, - { NULL, NULL } -}; - -void registerBitmapClass(lua_State * L) -{ - luaL_newmetatable(L, LUA_BITMAPHANDLE); - luaL_setfuncs(L, bitmapFuncs, 0); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - lua_setglobal(L, "Bitmap"); -} - -/*luadoc -@function lcd.drawBitmap(bitmap, x, y [, scale]) - -Displays a bitmap at (x,y) - -@param bitmap (pointer) point to a bitmap previously opened with Bitmap.open() - -@param x,y (positive numbers) starting coordinates - -@param scale (positive numbers) scale in %, 50 divides size by two, 100 is unchanged, 200 doubles size. -Omitting scale draws image in 1:1 scale and is faster than specifying 100 for scale. - -@notice Only available on Horus - -@status current Introduced in 2.2.0 -*/ -static int luaLcdDrawBitmap(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - const BitmapBuffer * b = checkBitmap(L, 1); - - if (b) { - unsigned int x = luaL_checkunsigned(L, 2); - unsigned int y = luaL_checkunsigned(L, 3); - unsigned int scale = luaL_optunsigned(L, 4, 0); - if (scale) { - lcd->drawBitmap(x, y, b, 0, 0, 0, 0, scale/100.0f); - } - else { - lcd->drawBitmap(x, y, b); - } - } - return 0; -} -#else -/*luadoc -@function lcd.drawPixmap(x, y, name) - -Draw a bitmap at (x,y) - -@param x,y (positive numbers) starting coordinates - -@param name (string) full path to the bitmap on SD card (i.e. “/IMAGES/test.bmp”) - -@notice Maximum image size is [display width / 2] x [display height] pixels. - -@status current Introduced in 2.0.0 -*/ -static int luaLcdDrawPixmap(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - const char * filename = luaL_checkstring(L, 3); - - uint8_t bitmap[BITMAP_BUFFER_SIZE(LCD_W/2, LCD_H)]; // width max is LCD_W/2 pixels for saving stack and avoid a malloc here - if (lcdLoadBitmap(bitmap, filename, LCD_W/2, LCD_H)) { - lcdDrawBitmap(x, y, bitmap); - } - - return 0; -} -#endif - -/*luadoc -@function lcd.drawRectangle(x, y, w, h [, flags [, t]]) - -Draw a rectangle from top left corner (x,y) of specified width and height - -@param x,y (positive numbers) top left corner position - -@param w (number) width in pixels - -@param h (number) height in pixels - -@param flags (unsigned number) drawing flags - -@param t (number) thickness in pixels, defaults to 1 (only on Horus) - -@status current Introduced in 2.0.0, changed in 2.2.0 -*/ -static int luaLcdDrawRectangle(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - int h = luaL_checkinteger(L, 4); - unsigned int flags = luaL_optunsigned(L, 5, 0); -#if defined(PCBHORUS) - unsigned int t = luaL_optunsigned(L, 6, 1); - lcdDrawRect(x, y, w, h, t, 0xff, flags); -#else - lcdDrawRect(x, y, w, h, 0xff, flags); -#endif - return 0; -} - -/*luadoc -@function lcd.drawFilledRectangle(x, y, w, h [, flags]) - -Draw a solid rectangle from top left corner (x,y) of specified width and height - -@param x,y (positive numbers) top left corner position - -@param w (number) width in pixels - -@param h (number) height in pixels - -@param flags (unsigned number) drawing flags - -@status current Introduced in 2.0.0 -*/ -static int luaLcdDrawFilledRectangle(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - int h = luaL_checkinteger(L, 4); - unsigned int flags = luaL_optunsigned(L, 5, 0); - lcdDrawFilledRect(x, y, w, h, SOLID, flags); - return 0; -} - - -/*luadoc -@function lcd.drawGauge(x, y, w, h, fill, maxfill [, flags]) - -Draw a simple gauge that is filled based upon fill value - -@param x,y (positive numbers) top left corner position - -@param w (number) width in pixels - -@param h (number) height in pixels - -@param fill (number) amount of fill to apply - -@param maxfill (number) total value of fill - -@param flags (unsigned number) drawing flags - -@status current Introduced in 2.0.0, changed in 2.2.0 -*/ -static int luaLcdDrawGauge(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - int h = luaL_checkinteger(L, 4); - int num = luaL_checkinteger(L, 5); - int den = luaL_checkinteger(L, 6); - unsigned int flags = luaL_optunsigned(L, 7, 0); -#if defined(PCBHORUS) - lcdDrawRect(x, y, w, h, 1, 0xff, flags); -#else - lcdDrawRect(x, y, w, h, 0xff, flags); -#endif - uint8_t len = limit((uint8_t)1, uint8_t(w*num/den), uint8_t(w)); - lcdDrawSolidFilledRect(x+1, y+1, len, h-2, flags); - return 0; -} - - -#if !defined(COLORLCD) -/*luadoc -@function lcd.drawScreenTitle(title, page, pages) - -Draw a title bar - -@param title (string) text for the title - -@param page (number) page number - -@param pages (number) total number of pages. Only used as indicator on -the right side of title bar. (i.e. idx=2, cnt=5, display `2/5`) - -@notice Only available on Taranis - -@status current Introduced in 2.0.0 -*/ -static int luaLcdDrawScreenTitle(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - const char * str = luaL_checkstring(L, 1); - int idx = luaL_checkinteger(L, 2); - int cnt = luaL_checkinteger(L, 3); - - if (cnt) drawScreenIndex(idx-1, cnt, 0); -#if LCD_DEPTH > 1 - lcdDrawFilledRect(0, 0, LCD_W, FH, SOLID, FILL_WHITE|GREY_DEFAULT); -#endif - title(str); - - return 0; -} -#endif - -#if !defined(COLORLCD) -/*luadoc -@function lcd.drawCombobox(x, y, w, list, idx [, flags]) - -Draw a combo box - -@param x,y (positive numbers) top left corner position - -@param w (number) width of combo box in pixels - -@param list (table) combo box elements, each element is a string - -@param idx (integer) index of entry to highlight - -@param flags (unsigned number) drawing flags, the flags can not be combined: - * `BLINK` combo box is expanded - * `INVERS` combo box collapsed, text inversed - * `0 or not present` combo box collapsed, text normal - -@notice Only available on Taranis - -@status current Introduced in 2.0.0 -*/ -static int luaLcdDrawCombobox(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - luaL_checktype(L, 4, LUA_TTABLE); - int count = luaL_len(L, 4); /* get size of table */ - int idx = luaL_checkinteger(L, 5); - unsigned int flags = luaL_optunsigned(L, 6, 0); - if (idx >= count) { - // TODO error - } - if (flags & BLINK) { - lcdDrawFilledRect(x, y, w-9, count*9+2, SOLID, ERASE); - lcdDrawRect(x, y, w-9, count*9+2); - for (int i=0; i> 16; - unsigned int color = luaL_checkunsigned(L, 2); - lcdColorTable[index] = color; - return 0; -} - -/*luadoc -@function lcd.getColor(area) - -Get the color for specific area : see lcd.setColor for area list - -@notice Only available on Colorlcd radios - -@status current Introduced in 2.3.11 -*/ - -static int luaLcdGetColor(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - - unsigned int index = luaL_checkunsigned(L, 1) >> 16; - lua_pushunsigned(L, lcdColorTable[index]); - return 1; -} - -/*luadoc -@function lcd.RGB(r, g, b) - -Returns a 5/6/5 rgb color code, that can be used with lcd.setColor - -@param r (integer) a number between 0x00 and 0xff that expresses te amount of red in the color - -@param g (integer) a number between 0x00 and 0xff that expresses te amount of green in the color - -@param b (integer) a number between 0x00 and 0xff that expresses te amount of blue in the color - -@retval number (integer) rgb color expressed in 5/6/5 format - -@notice Only available on Colorlcd radios - -@status current Introduced in 2.2.0 -*/ -static int luaRGB(lua_State *L) -{ - if (!luaLcdAllowed) - return 0; - int r = luaL_checkinteger(L, 1); - int g = luaL_checkinteger(L, 2); - int b = luaL_checkinteger(L, 3); - lua_pushinteger(L, RGB(r, g, b)); - return 1; -} -#endif - -const luaL_Reg lcdLib[] = { - { "refresh", luaLcdRefresh }, - { "clear", luaLcdClear }, - { "resetBacklightTimeout", luaLcdResetBacklightTimeout }, - { "drawPoint", luaLcdDrawPoint }, - { "drawLine", luaLcdDrawLine }, - { "drawRectangle", luaLcdDrawRectangle }, - { "drawFilledRectangle", luaLcdDrawFilledRectangle }, - { "drawText", luaLcdDrawText }, - { "drawTimer", luaLcdDrawTimer }, - { "drawNumber", luaLcdDrawNumber }, - { "drawChannel", luaLcdDrawChannel }, - { "drawSwitch", luaLcdDrawSwitch }, - { "drawSource", luaLcdDrawSource }, - { "drawGauge", luaLcdDrawGauge }, -#if defined(COLORLCD) - { "drawBitmap", luaLcdDrawBitmap }, - { "setColor", luaLcdSetColor }, - { "getColor", luaLcdGetColor }, - { "RGB", luaRGB }, -#else - { "getLastPos", luaLcdGetLastPos }, - { "getLastRightPos", luaLcdGetLastPos }, - { "getLastLeftPos", luaLcdGetLeftPos }, - { "drawPixmap", luaLcdDrawPixmap }, - { "drawScreenTitle", luaLcdDrawScreenTitle }, - { "drawCombobox", luaLcdDrawCombobox }, -#endif - { NULL, NULL } /* sentinel */ -}; diff --git a/radio/src/lua/api_model.cpp b/radio/src/lua/api_model.cpp index 842fb861378..472664fbd2b 100644 --- a/radio/src/lua/api_model.cpp +++ b/radio/src/lua/api_model.cpp @@ -19,6 +19,8 @@ * GNU General Public License for more details. */ +#define LUA_LIB + #include #include #include "opentx.h" @@ -1722,45 +1724,44 @@ static int luaModelSetSwashRing(lua_State *L) } #endif // HELI -const luaL_Reg modelLib[] = { - { "getInfo", luaModelGetInfo }, - { "setInfo", luaModelSetInfo }, - { "getModule", luaModelGetModule }, - { "setModule", luaModelSetModule }, - { "getTimer", luaModelGetTimer }, - { "setTimer", luaModelSetTimer }, - { "resetTimer", luaModelResetTimer }, - { "deleteFlightModes", luaModelDeleteFlightModes }, - { "getFlightMode", luaModelGetFlightMode }, - { "setFlightMode", luaModelSetFlightMode }, - { "getInputsCount", luaModelGetInputsCount }, - { "getInput", luaModelGetInput }, - { "insertInput", luaModelInsertInput }, - { "deleteInput", luaModelDeleteInput }, - { "deleteInputs", luaModelDeleteInputs }, - { "defaultInputs", luaModelDefaultInputs }, - { "getMixesCount", luaModelGetMixesCount }, - { "getMix", luaModelGetMix }, - { "insertMix", luaModelInsertMix }, - { "deleteMix", luaModelDeleteMix }, - { "deleteMixes", luaModelDeleteMixes }, - { "getLogicalSwitch", luaModelGetLogicalSwitch }, - { "setLogicalSwitch", luaModelSetLogicalSwitch }, - { "getCustomFunction", luaModelGetCustomFunction }, - { "setCustomFunction", luaModelSetCustomFunction }, - { "getCurve", luaModelGetCurve }, - { "setCurve", luaModelSetCurve }, - { "getOutput", luaModelGetOutput }, - { "setOutput", luaModelSetOutput }, +LROT_BEGIN(modellib, NULL, 0) + LROT_FUNCENTRY( getInfo, luaModelGetInfo ) + LROT_FUNCENTRY( setInfo, luaModelSetInfo ) + LROT_FUNCENTRY( getModule, luaModelGetModule ) + LROT_FUNCENTRY( setModule, luaModelSetModule ) + LROT_FUNCENTRY( getTimer, luaModelGetTimer ) + LROT_FUNCENTRY( setTimer, luaModelSetTimer ) + LROT_FUNCENTRY( resetTimer, luaModelResetTimer ) + LROT_FUNCENTRY( deleteFlightModes, luaModelDeleteFlightModes ) + LROT_FUNCENTRY( getFlightMode, luaModelGetFlightMode ) + LROT_FUNCENTRY( setFlightMode, luaModelSetFlightMode ) + LROT_FUNCENTRY( getInputsCount, luaModelGetInputsCount ) + LROT_FUNCENTRY( getInput, luaModelGetInput ) + LROT_FUNCENTRY( insertInput, luaModelInsertInput ) + LROT_FUNCENTRY( deleteInput, luaModelDeleteInput ) + LROT_FUNCENTRY( deleteInputs, luaModelDeleteInputs ) + LROT_FUNCENTRY( defaultInputs, luaModelDefaultInputs ) + LROT_FUNCENTRY( getMixesCount, luaModelGetMixesCount ) + LROT_FUNCENTRY( getMix, luaModelGetMix ) + LROT_FUNCENTRY( insertMix, luaModelInsertMix ) + LROT_FUNCENTRY( deleteMix, luaModelDeleteMix ) + LROT_FUNCENTRY( deleteMixes, luaModelDeleteMixes ) + LROT_FUNCENTRY( getLogicalSwitch, luaModelGetLogicalSwitch ) + LROT_FUNCENTRY( setLogicalSwitch, luaModelSetLogicalSwitch ) + LROT_FUNCENTRY( getCustomFunction, luaModelGetCustomFunction ) + LROT_FUNCENTRY( setCustomFunction, luaModelSetCustomFunction ) + LROT_FUNCENTRY( getCurve, luaModelGetCurve ) + LROT_FUNCENTRY( setCurve, luaModelSetCurve ) + LROT_FUNCENTRY( getOutput, luaModelGetOutput ) + LROT_FUNCENTRY( setOutput, luaModelSetOutput ) #if defined (GVARS) - { "getGlobalVariable", luaModelGetGlobalVariable }, - { "setGlobalVariable", luaModelSetGlobalVariable }, + LROT_FUNCENTRY( getGlobalVariable, luaModelGetGlobalVariable ) + LROT_FUNCENTRY( setGlobalVariable, luaModelSetGlobalVariable ) #endif - { "getSensor", luaModelGetSensor }, - { "resetSensor", luaModelResetSensor }, + LROT_FUNCENTRY( getSensor, luaModelGetSensor ) + LROT_FUNCENTRY( resetSensor, luaModelResetSensor ) #if defined(HELI) - { "getSwashRing", luaModelGetSwashRing }, - { "setSwashRing", luaModelSetSwashRing }, + LROT_FUNCENTRY( getSwashRing, luaModelGetSwashRing ) + LROT_FUNCENTRY( setSwashRing, luaModelSetSwashRing ) #endif - { nullptr, nullptr } /* sentinel */ -}; +LROT_END(modellib, NULL, 0) diff --git a/radio/src/lua/api_stdlcd.cpp b/radio/src/lua/api_stdlcd.cpp index 7f52aa7424d..2342cddb7bb 100644 --- a/radio/src/lua/api_stdlcd.cpp +++ b/radio/src/lua/api_stdlcd.cpp @@ -620,26 +620,25 @@ static int luaLcdDrawCombobox(lua_State *L) return 0; } -const luaL_Reg lcdLib[] = { - { "refresh", luaLcdRefresh }, - { "clear", luaLcdClear }, - { "resetBacklightTimeout", luaLcdResetBacklightTimeout }, - { "drawPoint", luaLcdDrawPoint }, - { "drawLine", luaLcdDrawLine }, - { "drawRectangle", luaLcdDrawRectangle }, - { "drawFilledRectangle", luaLcdDrawFilledRectangle }, - { "drawText", luaLcdDrawText }, - { "drawTimer", luaLcdDrawTimer }, - { "drawNumber", luaLcdDrawNumber }, - { "drawChannel", luaLcdDrawChannel }, - { "drawSwitch", luaLcdDrawSwitch }, - { "drawSource", luaLcdDrawSource }, - { "drawGauge", luaLcdDrawGauge }, - { "getLastPos", luaLcdGetLastPos }, - { "getLastRightPos", luaLcdGetLastPos }, - { "getLastLeftPos", luaLcdGetLeftPos }, - { "drawPixmap", luaLcdDrawPixmap }, - { "drawScreenTitle", luaLcdDrawScreenTitle }, - { "drawCombobox", luaLcdDrawCombobox }, - { NULL, NULL } /* sentinel */ -}; +LROT_BEGIN(lcdlib, NULL, 0) + LROT_FUNCENTRY( refresh, luaLcdRefresh ) + LROT_FUNCENTRY( clear, luaLcdClear ) + LROT_FUNCENTRY( resetBacklightTimeout, luaLcdResetBacklightTimeout ) + LROT_FUNCENTRY( drawPoint, luaLcdDrawPoint ) + LROT_FUNCENTRY( drawLine, luaLcdDrawLine ) + LROT_FUNCENTRY( drawRectangle, luaLcdDrawRectangle ) + LROT_FUNCENTRY( drawFilledRectangle, luaLcdDrawFilledRectangle ) + LROT_FUNCENTRY( drawText, luaLcdDrawText ) + LROT_FUNCENTRY( drawTimer, luaLcdDrawTimer ) + LROT_FUNCENTRY( drawNumber, luaLcdDrawNumber ) + LROT_FUNCENTRY( drawChannel, luaLcdDrawChannel ) + LROT_FUNCENTRY( drawSwitch, luaLcdDrawSwitch ) + LROT_FUNCENTRY( drawSource, luaLcdDrawSource ) + LROT_FUNCENTRY( drawGauge, luaLcdDrawGauge ) + LROT_FUNCENTRY( getLastPos, luaLcdGetLastPos ) + LROT_FUNCENTRY( getLastRightPos, luaLcdGetLastPos ) + LROT_FUNCENTRY( getLastLeftPos, luaLcdGetLeftPos ) + LROT_FUNCENTRY( drawPixmap, luaLcdDrawPixmap ) + LROT_FUNCENTRY( drawScreenTitle, luaLcdDrawScreenTitle ) + LROT_FUNCENTRY( drawCombobox, luaLcdDrawCombobox ) +LROT_END(lcdlib, NULL, 0) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 68101ff5787..7b40c86c4af 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -36,7 +36,6 @@ #include "switches.h" #if defined(LIBOPENUI) - #include "api_colorlcd.h" #include "libopenui.h" #else #include "libopenui/src/libopenui_file.h" @@ -273,14 +272,11 @@ void luaClose(lua_State ** L) } } + void luaRegisterLibraries(lua_State * L) { luaL_openlibs(L); - registerDirIter(L); - -#if defined(COLORLCD) - registerBitmapClass(L); -#endif + lua_settop(L, 0); } #define GC_REPORT_TRESHOLD (2*1024) @@ -781,6 +777,39 @@ void luaError(lua_State * L, uint8_t error) TRACE_ERROR("%s\n", lua_warning_info); } +// static void luaDumpStack (lua_State *L) { +// int top=lua_gettop(L); +// for (int i=1; i <= top; i++) { +// printf("%d\t%s\t", i, luaL_typename(L,i)); +// switch (lua_type(L, i)) { +// case LUA_TNUMBER: +// printf("%g\n",lua_tonumber(L,i)); +// break; +// case LUA_TSTRING: +// printf("%s\n",lua_tostring(L,i)); +// break; +// case LUA_TBOOLEAN: +// printf("%s\n", (lua_toboolean(L, i) ? "true" : "false")); +// break; +// case LUA_TNIL: +// printf("%s\n", "nil"); +// break; +// case LUA_TTABLE: { +// lua_pushnil(L); +// while(lua_next(L,i)) { +// const char* key = lua_tostring(L,-2); +// const char* val = lua_tostring(L,-1); +// printf("\t%s = %s\n", key, val); +// lua_pop(L,1); +// } +// } break; +// default: +// printf("%p\n",lua_topointer(L,i)); +// break; +// } +// } +// } + // Register a function from a table on the top of the stack static int luaRegisterFunction(const char * key) { diff --git a/radio/src/lua/lua_api.h b/radio/src/lua/lua_api.h index 632228ee5f6..5cef63088ac 100644 --- a/radio/src/lua/lua_api.h +++ b/radio/src/lua/lua_api.h @@ -31,7 +31,6 @@ extern "C" { #include #include #include - #include #include } @@ -62,7 +61,31 @@ extern lua_State * lsScripts; extern bool luaLcdAllowed; #if defined(COLORLCD) -extern lua_State * lsWidgets; +// +// Obsoleted definitions: +// -> please check against libopenui_defines.h for conflicts +// -> here we use the 4 most significant bits for our flags (32 bit unsigned) +// +// INVERS & BLINK are used in most scripts, let's offer a compatibility mode. +// +#undef INVERS +#undef BLINK + +#define INVERS 0x01u +#define BLINK 0x1000u +#define RGB_FLAG 0x8000u + +extern bool luaLcdAllowed; + +class BitmapBuffer; +extern BitmapBuffer* luaLcdBuffer; + +class Widget; +extern Widget* runningFS; + +LcdFlags flagsRGB(LcdFlags flags); + +extern lua_State* lsWidgets; extern uint32_t luaExtraMemoryUsage; void luaInitThemesAndWidgets(); #endif diff --git a/radio/src/lua/lua_widget.cpp b/radio/src/lua/lua_widget.cpp index d980a6c916f..9424ee8935f 100644 --- a/radio/src/lua/lua_widget.cpp +++ b/radio/src/lua/lua_widget.cpp @@ -24,7 +24,6 @@ #include "lua_api.h" #include "lua_event.h" -#include "api_colorlcd.h" #include "draw_functions.h" #define MAX_INSTRUCTIONS (20000/100) diff --git a/radio/src/lua/lua_widget_factory.cpp b/radio/src/lua/lua_widget_factory.cpp index 73badb12f9b..7ba4397c07f 100644 --- a/radio/src/lua/lua_widget_factory.cpp +++ b/radio/src/lua/lua_widget_factory.cpp @@ -23,7 +23,6 @@ #include "lua_widget.h" #include "lua_api.h" -#include "api_colorlcd.h" #define MAX_INSTRUCTIONS (20000/100) diff --git a/radio/src/lua/widgets.cpp b/radio/src/lua/widgets.cpp index 88b054f2d89..ad3be8e2f26 100644 --- a/radio/src/lua/widgets.cpp +++ b/radio/src/lua/widgets.cpp @@ -21,12 +21,12 @@ #include #include + #include "opentx.h" -#include "bin_allocator.h" #include "lua_api.h" + #include "widget.h" #include "libopenui_file.h" -#include "api_colorlcd.h" #include "view_main.h" #include "lua_widget.h" @@ -35,13 +35,6 @@ #define MAX_INSTRUCTIONS (20000/100) #define LUA_WARNING_INFO_LEN 64 -// #if defined(HARDWARE_TOUCH) -// #include "touch.h" -// #define EVT_TOUCH_SWIPE_LOCK 4 -// #define EVT_TOUCH_SWIPE_SPEED 60 -// #define EVT_TOUCH_SWIPE_TIMEOUT 50 -// #endif - lua_State * lsWidgets = NULL; extern int custom_lua_atpanic(lua_State *L); @@ -49,8 +42,7 @@ extern int custom_lua_atpanic(lua_State *L); #define LUA_WIDGET_FILENAME "/main.lua" #define LUA_FULLPATH_MAXLEN \ (LEN_FILE_PATH_MAX + LEN_SCRIPT_FILENAME + \ - LEN_FILE_EXTENSION_MAX) // max length (example: - // /SCRIPTS/THEMES/mytheme.lua) + LEN_FILE_EXTENSION_MAX) static void luaHook(lua_State *L, lua_Debug *ar) { diff --git a/radio/src/thirdparty/Lua/src/lapi.c b/radio/src/thirdparty/Lua/src/lapi.c index 50d2a3b7e24..fb0fae017b7 100644 --- a/radio/src/thirdparty/Lua/src/lapi.c +++ b/radio/src/thirdparty/Lua/src/lapi.c @@ -23,7 +23,6 @@ #include "lstate.h" #include "lstring.h" #include "ltable.h" -#include "lrotable.h" #include "ltm.h" #include "lundump.h" #include "lvm.h" @@ -407,10 +406,11 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { LUA_API size_t lua_rawlen (lua_State *L, int idx) { StkId o = index2addr(L, idx); - switch (ttypenv(o)) { - case LUA_TSTRING: return tsvalue(o)->len; + switch (ttype(o)) { + case LUA_TSHRSTR: + case LUA_TLNGSTR: return tsvalue(o)->len; case LUA_TUSERDATA: return uvalue(o)->len; - case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TTBLRAM: return luaH_getn(hvalue(o)); default: return 0; } } @@ -444,7 +444,8 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) { LUA_API const void *lua_topointer (lua_State *L, int idx) { StkId o = index2addr(L, idx); switch (ttype(o)) { - case LUA_TTABLE: return hvalue(o); + case LUA_TTBLRAM: + case LUA_TTBLROF: return hvalue(o); case LUA_TLCL: return clLvalue(o); case LUA_TCCL: return clCvalue(o); case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o))); @@ -452,8 +453,6 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA: return lua_touserdata(L, idx); - case LUA_TROTABLE: - return pvalue(o); default: return NULL; } } @@ -575,6 +574,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { lua_unlock(L); } + LUA_API void lua_pushboolean (lua_State *L, int b) { lua_lock(L); setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ @@ -590,21 +590,24 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { lua_unlock(L); } -LUA_API void lua_pushrotable (lua_State *L, void *p) { + +LUA_API int lua_pushthread (lua_State *L) { lua_lock(L); - setrvalue(L->top, p); + setthvalue(L, L->top, L); api_incr_top(L); lua_unlock(L); + return (G(L)->mainthread == L); } -LUA_API int lua_pushthread (lua_State *L) { + +LUA_API void lua_pushrotable (lua_State *L, const ROTable *t) { lua_lock(L); - setthvalue(L, L->top, L); + sethvalue(L, L->top, cast(Table *, t)); api_incr_top(L); lua_unlock(L); - return (G(L)->mainthread == L); } + /* ** get functions (Lua -> stack) */ @@ -614,11 +617,9 @@ LUA_API void lua_getglobal (lua_State *L, const char *var) { Table *reg = hvalue(&G(L)->l_registry); const TValue *gt; /* global table */ lua_lock(L); + gt = luaH_getint(reg, LUA_RIDX_GLOBALS); setsvalue2s(L, L->top++, luaS_new(L, var)); - if (!luaR_findglobal(L, var, L->top - 1)) { - gt = luaH_getint(reg, LUA_RIDX_GLOBALS); - luaV_gettable(L, gt, L->top - 1, L->top - 1); - } + luaV_gettable(L, gt, L->top - 1, L->top - 1); lua_unlock(L); } @@ -779,7 +780,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { lua_lock(L); api_checknelems(L, 2); t = index2addr(L, idx); - api_check(L, ttistable(t), "table expected"); + api_check(L, ttisrwtable(t), "RW table expected"); setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); invalidateTMcache(hvalue(t)); luaC_barrierback(L, gcvalue(t), L->top-1); @@ -793,7 +794,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { lua_lock(L); api_checknelems(L, 1); t = index2addr(L, idx); - api_check(L, ttistable(t), "table expected"); + api_check(L, ttisrwtable(t), "RW table expected"); luaH_setint(L, hvalue(t), n, L->top - 1); luaC_barrierback(L, gcvalue(t), L->top-1); L->top--; @@ -807,7 +808,7 @@ LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { lua_lock(L); api_checknelems(L, 1); t = index2addr(L, idx); - api_check(L, ttistable(t), "table expected"); + api_check(L, ttisrwtable(t), "RW table expected"); setpvalue(&k, cast(void *, p)); setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); luaC_barrierback(L, gcvalue(t), L->top - 1); @@ -828,8 +829,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { api_check(L, ttistable(L->top - 1), "table expected"); mt = hvalue(L->top - 1); } - switch (ttypenv(obj)) { - case LUA_TTABLE: { + switch (ttype(obj)) { + case LUA_TTBLRAM: { hvalue(obj)->metatable = mt; if (mt) { luaC_objbarrierback(L, gcvalue(obj), mt); @@ -837,6 +838,9 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { } break; } + case LUA_TTBLROF: { + luai_apicheck(L, "RW table expected"); + } case LUA_TUSERDATA: { uvalue(obj)->metatable = mt; if (mt) { diff --git a/radio/src/thirdparty/Lua/src/lauxlib.c b/radio/src/thirdparty/Lua/src/lauxlib.c index b8bcdda46f5..b3ef28d4a91 100644 --- a/radio/src/thirdparty/Lua/src/lauxlib.c +++ b/radio/src/thirdparty/Lua/src/lauxlib.c @@ -298,6 +298,18 @@ LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { } +LUALIB_API int luaL_rometatable (lua_State *L, const char* tname, const ROTable *p) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_pushrotable(L, p); + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { void *p = lua_touserdata(L, ud); if (p != NULL) { /* value is a userdata? */ @@ -923,16 +935,32 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { */ LUALIB_API void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) { - lua_pushcfunction(L, openf); - lua_pushstring(L, modname); /* argument to open function */ - lua_call(L, 1, 1); /* open module */ + int inROM = 0; luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_pushvalue(L, -2); /* make copy of module (call result) */ - lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ - lua_pop(L, 1); /* remove _LOADED table */ + lua_getfield(L, -1, modname); /* LOADED[modname] */ + if (!lua_toboolean(L, -1)) { /* package not in LOADED table? */ + lua_getglobal(L, "ROM"); /* try the ROM entry */ + if(!lua_isnil(L,-1)) { + lua_getfield(L, -1, modname); /* ROM[name] */ + inROM = lua_toboolean(L, -1); + lua_pop(L, 3); + } else + lua_pop(L, 2); + + if (inROM) /* package is in ROM */ + glb = 0; /* suppress setting _G entry */ + lua_pushcfunction(L, openf); + lua_pushstring(L, modname); /* argument to open function */ + lua_call(L, 1, 1); /* call 'openf' to open module */ + if (lua_toboolean(L, -1) && !inROM) { /* if not in ROM & result is returned */ + lua_pushvalue(L, -1); /* make copy of module (call result) */ + lua_setfield(L, -3, modname); /* LOADED[modname] = module */ + } + } + lua_remove(L, -2); /* remove LOADED table */ if (glb) { - lua_pushvalue(L, -1); /* copy of 'mod' */ - lua_setglobal(L, modname); /* _G[modname] = module */ + lua_pushvalue(L, -1); /* copy of module */ + lua_setglobal(L, modname); /* _G[modname] = module */ } } diff --git a/radio/src/thirdparty/Lua/src/lauxlib.h b/radio/src/thirdparty/Lua/src/lauxlib.h index 9cd4c02d387..a9f9e8e4393 100644 --- a/radio/src/thirdparty/Lua/src/lauxlib.h +++ b/radio/src/thirdparty/Lua/src/lauxlib.h @@ -13,6 +13,9 @@ #include "lua.h" +#ifdef LUA_LIB +#include "lro_defs.h" +#endif /* extra error code for `luaL_load' */ @@ -62,6 +65,9 @@ LUALIB_API void (luaL_checkany) (lua_State *L, int narg); LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); + +LUALIB_API int (luaL_rometatable) (lua_State *L, const char* tname, const ROTable *p); + LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); diff --git a/radio/src/thirdparty/Lua/src/lbaselib.c b/radio/src/thirdparty/Lua/src/lbaselib.c index 806c8e0b548..095e0524b59 100644 --- a/radio/src/thirdparty/Lua/src/lbaselib.c +++ b/radio/src/thirdparty/Lua/src/lbaselib.c @@ -4,19 +4,22 @@ ** See Copyright Notice in lua.h */ - +#define lbaselib_c +#define LUA_LIB #include +#include #include #include -#define lbaselib_c - #include "lua.h" #include "lauxlib.h" #include "lualib.h" -#include "lrotable.h" + +// ROTable +#include "lobject.h" + static int luaB_print (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ @@ -411,39 +414,44 @@ static int luaB_tostring (lua_State *L) { return 1; } -const luaL_Reg baselib[] = { - {"assert", luaB_assert}, - {"collectgarbage", luaB_collectgarbage}, - {"dofile", luaB_dofile}, - {"error", luaB_error}, - {"getmetatable", luaB_getmetatable}, - {"ipairs", luaB_ipairs}, - {"loadfile", luaB_loadfile}, - {"load", luaB_load}, +extern LROT_TABLE(etxlib); + +LROT_BEGIN(base_func, NULL, 0) + LROT_FUNCENTRY(assert, luaB_assert) + LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage) + LROT_FUNCENTRY(dofile, luaB_dofile) + LROT_FUNCENTRY(error, luaB_error) + LROT_FUNCENTRY(getmetatable, luaB_getmetatable) + LROT_FUNCENTRY(ipairs, luaB_ipairs) + LROT_FUNCENTRY(loadfile, luaB_loadfile) + LROT_FUNCENTRY(load, luaB_load) #if defined(LUA_COMPAT_LOADSTRING) - {"loadstring", luaB_load}, -#endif - {"next", luaB_next}, - {"pairs", luaB_pairs}, - {"pcall", luaB_pcall}, - {"print", luaB_print}, - {"rawequal", luaB_rawequal}, - {"rawlen", luaB_rawlen}, - {"rawget", luaB_rawget}, - {"rawset", luaB_rawset}, - {"select", luaB_select}, - {"setmetatable", luaB_setmetatable}, - {"tonumber", luaB_tonumber}, - {"tostring", luaB_tostring}, - {"type", luaB_type}, - {"xpcall", luaB_xpcall}, - {NULL, NULL} -}; - -#if 0 -// TODO -const luaR_value_entry baselib_vals[] = { - {"_VERSION", LUA_VERSION}, - {NULL, 0} -}; + LROT_FUNCENTRY(loadstring, luaB_load) #endif + LROT_FUNCENTRY(next, luaB_next) + LROT_FUNCENTRY(pairs, luaB_pairs) + LROT_FUNCENTRY(pcall, luaB_pcall) + LROT_FUNCENTRY(print, luaB_print) + LROT_FUNCENTRY(rawequal, luaB_rawequal) + LROT_FUNCENTRY(rawlen, luaB_rawlen) + LROT_FUNCENTRY(rawget, luaB_rawget) + LROT_FUNCENTRY(rawset, luaB_rawset) + LROT_FUNCENTRY(select, luaB_select) + LROT_FUNCENTRY(setmetatable, luaB_setmetatable) + LROT_FUNCENTRY(tonumber, luaB_tonumber) + LROT_FUNCENTRY(tostring, luaB_tostring) + LROT_FUNCENTRY(type, luaB_type) + LROT_FUNCENTRY(xpcall, luaB_xpcall) +LROT_END(base_func, NULL, 0) + +extern LROT_TABLE(rotables); +LUAMOD_API int luaopen_base (lua_State *L) { + lua_pushglobaltable(L); /* set global _G */ + lua_pushliteral(L, LUA_VERSION); /* set global _VERSION */ + lua_setfield(L, -2, "_VERSION"); + lua_createtable (L, 0, 1); /* mt for _G */ + lua_pushrotable(L, LROT_TABLEREF(rotables)); + lua_setfield(L, -2, "__index"); /* mt.__index=ROM table */ + lua_setmetatable(L, -2); + return 1; /* returns _G */ +} diff --git a/radio/src/thirdparty/Lua/src/lbitlib.c b/radio/src/thirdparty/Lua/src/lbitlib.c index 4862af7129d..a52d4401a14 100644 --- a/radio/src/thirdparty/Lua/src/lbitlib.c +++ b/radio/src/thirdparty/Lua/src/lbitlib.c @@ -5,14 +5,13 @@ */ #define lbitlib_c +#define LUA_LIB #include "lua.h" #include "lauxlib.h" #include "lualib.h" -#include "lrotable.h" - /* number of bits to consider in a number */ #if !defined(LUA_NBITS) #define LUA_NBITS 32 @@ -186,26 +185,25 @@ static int b_replace (lua_State *L) { } -const luaL_Reg bitlib[] = { - {"arshift", b_arshift}, - {"band", b_and}, - {"bnot", b_not}, - {"bor", b_or}, - {"bxor", b_xor}, - {"btest", b_test}, - {"extract", b_extract}, - {"lrotate", b_lrot}, - {"lshift", b_lshift}, - {"replace", b_replace}, - {"rrotate", b_rrot}, - {"rshift", b_rshift}, - {NULL, NULL} -}; +LROT_BEGIN(bitlib, NULL, 0) + LROT_FUNCENTRY( arshift, b_arshift ) + LROT_FUNCENTRY( band, b_and ) + LROT_FUNCENTRY( bnot, b_not ) + LROT_FUNCENTRY( bor, b_or ) + LROT_FUNCENTRY( bxor, b_xor ) + LROT_FUNCENTRY( btest, b_test ) + LROT_FUNCENTRY( extract, b_extract ) + LROT_FUNCENTRY( lrotate, b_lrot ) + LROT_FUNCENTRY( lshift, b_lshift ) + LROT_FUNCENTRY( replace, b_replace ) + LROT_FUNCENTRY( rrotate, b_rrot ) + LROT_FUNCENTRY( rshift, b_rshift ) +LROT_END(bitlib, NULL, 0) -const luaR_value_entry bitlib_vals[] = { - {NULL, 0} -}; +/* +** Open bit library +*/ LUAMOD_API int luaopen_bit32 (lua_State *L) { return 0; } diff --git a/radio/src/thirdparty/Lua/src/linit.c b/radio/src/thirdparty/Lua/src/linit.c index 05ef2083fce..58d9886ad47 100644 --- a/radio/src/thirdparty/Lua/src/linit.c +++ b/radio/src/thirdparty/Lua/src/linit.c @@ -14,72 +14,109 @@ #define linit_c +#define LUA_LIB #include "lua.h" - #include "lualib.h" #include "lauxlib.h" -#include "lrotable.h" +#include "lstring.h" +#include "ltable.h" +#include "lstate.h" +#include "lgc.h" -/* -** these libs are loaded by lua.c and are readily available to any Lua -** program -*/ -static const luaL_Reg loadedlibs[] = { - // {"_G", luaopen_base}, -#if defined(COLORLCD) - {LUA_LOADLIBNAME, luaopen_package}, -#endif - // {LUA_COLIBNAME, luaopen_coroutine}, - // {LUA_TABLIBNAME, luaopen_table}, - {LUA_IOLIBNAME, luaopen_io}, - // {LUA_OSLIBNAME, luaopen_os}, - // {LUA_STRLIBNAME, luaopen_string}, - // {LUA_BITLIBNAME, luaopen_bit32}, - // {LUA_MATHLIBNAME, luaopen_math}, - // {LUA_DBLIBNAME, luaopen_debug}, - {NULL, NULL} +#include "lua/api_filesystem.h" +#include "lua/api_colorlcd.h" + +extern LROT_TABLE(iolib); +extern LROT_TABLE(strlib); +extern LROT_TABLE(mathlib); +extern LROT_TABLE(bitlib); + +extern LROT_TABLE(etxlib); +extern LROT_TABLE(etxcst); +extern LROT_TABLE(etxstr); +extern LROT_TABLE(etxdir); + +extern LROT_TABLE(lcdlib); +extern LROT_TABLE(modellib); +extern LROT_TABLE(bitmaplib); + +/* _G __index -> rotables __index -> _index_hook_fct */ +extern LROT_TABLE(rotables_meta); +extern LROT_TABLE(base_func); + +static const ROTable* _global_symbols[] = { + LROT_TABLEREF(base_func), + LROT_TABLEREF(etxlib), + LROT_TABLEREF(etxdir), + LROT_TABLEREF(etxcst), + LROT_TABLEREF(etxstr), + NULL, }; -/* The read-only tables are defined here */ -const luaR_table lua_rotable[] = +static int _index_hook_fct(lua_State * L) { - {"__opentx", opentxLib, opentxConstants, edgetxStrings}, - {"lcd", lcdLib, NULL, NULL}, - {"model", modelLib, NULL, NULL}, - {"__baselib", baselib, NULL, NULL}, - {LUA_IOLIBNAME, iolib, NULL, NULL}, - {LUA_STRLIBNAME, strlib, NULL, NULL}, - {LUA_MATHLIBNAME, mathlib, mathlib_vals, NULL}, - {LUA_BITLIBNAME, bitlib, NULL, NULL}, -#if defined(COLORLCD) - {LUA_TABLIBNAME, tab_funcs, NULL, NULL}, -#endif - {NULL, NULL, NULL, NULL} -}; + const ROTable** t = _global_symbols; + const TValue* res = luaO_nilobject; + TString* key; -/* -** these libs are preloaded and must be required before used -*/ -static const luaL_Reg preloadedlibs[] = { - {NULL, NULL} -}; + lua_lock(L); + key = rawtsvalue(L->top - 1); + for(; *t; t++) { + res = luaH_getstr((Table*)*t, key); + if (!ttisnil(res)) break; + } + + if (ttislightuserdata(res)) { + /* strings are encoded as light user data */ + setsvalue2s(L, L->top - 1, luaS_new(L, pvalue(res))); + } else { + setobj2s(L, L->top - 1, res); + } + lua_unlock(L); + + return 1; +} + +/* rotables is inserted in luaopen_base */ +LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX) + LROT_FUNCENTRY( __index, _index_hook_fct ) +LROT_END(rotables_meta, NULL, LROT_MASK_INDEX) + +LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0) + LROT_TABENTRY( _G, base_func) + LROT_TABENTRY( io, iolib ) + LROT_TABENTRY( string, strlib ) + LROT_TABENTRY( math, mathlib ) + LROT_TABENTRY( bit, bitlib ) + LROT_TABENTRY( lcd, lcdlib ) + LROT_TABENTRY( model, modellib ) + LROT_TABENTRY( bitmap, bitmaplib ) + LROT_TABENTRY( Bitmap, bitmaplib ) /* TODO: obsolete after 2.9 */ + LROT_TABENTRY( ROM, rotables ) +LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0) + +LROT_BEGIN(lua_libs, NULL, 0) + LROT_FUNCENTRY( _G, luaopen_base ) + LROT_FUNCENTRY( io, luaopen_io ) + LROT_FUNCENTRY( dir, luaopen_etxdir ) + LROT_FUNCENTRY( bitmap_mt, luaopen_bitmap ) +#if defined(LUA_ENABLE_LOADLIB) + LROT_FUNCENTRY( package, luaopen_package ) +#endif +#if defined(LUA_ENABLE_STRLIB_MT) + LROT_FUNCENTRY( string, luaopen_string ) +#endif +LROT_END(lua_libs, NULL, 0) LUALIB_API void luaL_openlibs (lua_State *L) { - const luaL_Reg *lib; - /* call open functions from 'loadedlibs' and set results to global table */ - for (lib = loadedlibs; lib->func; lib++) { - luaL_requiref(L, lib->name, lib->func, 1); - lua_pop(L, 1); /* remove lib */ - } - /* add open functions from 'preloadedlibs' into 'package.preload' table */ - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); - for (lib = preloadedlibs; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_setfield(L, -2, lib->name); + const ROTable_entry *p = LROT_TABLEREF(lua_libs)->entry; + /* Now do lua opens */ + for ( ; p->key; p++) { + if (ttislcf(&p->value) && fvalue(&p->value)) + luaL_requiref(L, p->key, fvalue(&p->value), 1); } - lua_pop(L, 1); /* remove _PRELOAD table */ } diff --git a/radio/src/thirdparty/Lua/src/liolib.c b/radio/src/thirdparty/Lua/src/liolib.c index 33545a96859..4d4a9a17ffc 100644 --- a/radio/src/thirdparty/Lua/src/liolib.c +++ b/radio/src/thirdparty/Lua/src/liolib.c @@ -4,7 +4,6 @@ ** See Copyright Notice in lua.h */ - /* ** POSIX idiosyncrasy! ** This definition must come before the inclusion of 'stdio.h'; it @@ -14,15 +13,14 @@ #define _FILE_OFFSET_BITS 64 #endif - +#define liolib_c +#define LUA_LIB #include #include #include #include -#define liolib_c - #include "lua.h" #include "lauxlib.h" @@ -649,84 +647,25 @@ static int io_seek (lua_State *L) { /* ** functions for 'io' library */ -const luaL_Reg iolib[] = { - {"close", io_close}, - // {"flush", io_flush}, - // {"input", io_input}, - // {"lines", io_lines}, - {"seek", io_seek}, - {"open", io_open}, - // {"output", io_output}, - // {"popen", io_popen}, - {"read", io_read}, - // {"tmpfile", io_tmpfile}, - // {"type", io_type}, - {"write", io_write}, - {NULL, NULL} -}; +LROT_BEGIN(iolib, NULL, 0) + LROT_FUNCENTRY( close, io_close ) + LROT_FUNCENTRY( seek, io_seek ) + LROT_FUNCENTRY( open, io_open ) + LROT_FUNCENTRY( read, io_read ) + LROT_FUNCENTRY( write, io_write ) +LROT_END(iolib, NULL, 0) /* ** methods for file handles +** +** we define only garbage collector to close any leftover open files */ -static const luaL_Reg flib[] = { - // {"close", io_close}, - // {"flush", f_flush}, - // {"lines", f_lines}, - // {"read", io_read}, - // {"seek", f_seek}, - // {"setvbuf", f_setvbuf}, - // {"write", f_write}, - {"__gc", f_gc}, // we define only garbage collector to close any leftover open files - // {"__tostring", f_tostring}, - {NULL, NULL} -}; - -static void createmeta (lua_State *L) { - luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ - lua_pushvalue(L, -1); /* push metatable */ - lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */ - lua_pop(L, 1); /* pop new metatable */ -} +LROT_BEGIN(file_handle, NULL, LROT_MASK_GC) + LROT_FUNCENTRY( __gc, f_gc ) +LROT_END(file_handle, NULL, LROT_MASK_GC) -#if !defined(USE_FATFS) -/* -** function to (not) close the standard files stdin, stdout, and stderr -*/ -static int io_noclose (lua_State *L) { - LStream *p = tolstream(L); - p->closef = &io_noclose; /* keep file opened */ - lua_pushnil(L); - lua_pushliteral(L, "cannot close standard file"); - return 2; -} - - -static void createstdfile (lua_State *L, FILE *f, const char *k, - const char *fname) { - LStream *p = newprefile(L); - p->f = f; - p->closef = &io_noclose; - if (k != NULL) { - lua_pushvalue(L, -1); - lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */ - } - lua_setfield(L, -2, fname); /* add file to module */ -} - -#endif LUAMOD_API int luaopen_io (lua_State *L) { - // luaL_newlib(L, iolib); /* new module */ - createmeta(L); - /* create (and set) default files */ - // createstdfile(L, stdin, IO_INPUT, "stdin"); - // createstdfile(L, stdout, IO_OUTPUT, "stdout"); - // createstdfile(L, stderr, NULL, "stderr"); - // return 1; + luaL_rometatable( L, LUA_FILEHANDLE, LROT_TABLEREF(file_handle)); return 0; } - -#if defined(USE_FATFS) - #undef FILE -#endif diff --git a/radio/src/thirdparty/Lua/src/llimits.h b/radio/src/thirdparty/Lua/src/llimits.h index b278d48808f..cad8bb36608 100644 --- a/radio/src/thirdparty/Lua/src/llimits.h +++ b/radio/src/thirdparty/Lua/src/llimits.h @@ -145,6 +145,17 @@ typedef lu_int32 Instruction; #endif +/* +** Size of cache for strings in the API. 'N' is the number of +** sets (better be a prime) and "M" is the size of each set (M == 1 +** makes a direct cache.) +*/ +#if !defined(KEYCACHE_N) +#define KEYCACHE_N 32 +#define KEYCACHE_M 4 +#endif + + /* minimum size for string buffer */ #if !defined(LUA_MINBUFFER) #define LUA_MINBUFFER 32 diff --git a/radio/src/thirdparty/Lua/src/lmathlib.c b/radio/src/thirdparty/Lua/src/lmathlib.c index 75ad5f2a836..5cd2fa6dd30 100644 --- a/radio/src/thirdparty/Lua/src/lmathlib.c +++ b/radio/src/thirdparty/Lua/src/lmathlib.c @@ -4,19 +4,17 @@ ** See Copyright Notice in lua.h */ +#define lmathlib_c +#define LUA_LIB #include #include -#define lmathlib_c - #include "lua.h" #include "lauxlib.h" #include "lualib.h" -#include "lrotable.h" - #undef PI #define PI ((lua_Number)(3.1415926535897932384626433832795)) #define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0)) @@ -229,45 +227,42 @@ static int math_randomseed (lua_State *L) { return 0; } -const luaL_Reg mathlib[] = { - {"abs", math_abs}, - {"acos", math_acos}, - {"asin", math_asin}, - {"atan2", math_atan2}, - {"atan", math_atan}, - {"ceil", math_ceil}, - {"cosh", math_cosh}, - {"cos", math_cos}, - {"deg", math_deg}, - {"exp", math_exp}, - {"floor", math_floor}, - {"fmod", math_fmod}, - {"frexp", math_frexp}, - {"ldexp", math_ldexp}, + +LROT_BEGIN(mathlib, NULL, 0) + LROT_FUNCENTRY( abs, math_abs) + LROT_FUNCENTRY( acos, math_acos) + LROT_FUNCENTRY( asin, math_asin) + LROT_FUNCENTRY( atan2, math_atan2) + LROT_FUNCENTRY( atan, math_atan) + LROT_FUNCENTRY( ceil, math_ceil) + LROT_FUNCENTRY( cosh, math_cosh) + LROT_FUNCENTRY( cos, math_cos) + LROT_FUNCENTRY( deg, math_deg) + LROT_FUNCENTRY( exp, math_exp) + LROT_FUNCENTRY( floor, math_floor) + LROT_FUNCENTRY( fmod, math_fmod) + LROT_FUNCENTRY( frexp, math_frexp) + LROT_FUNCENTRY( ldexp, math_ldexp) #if defined(LUA_COMPAT_LOG10) - {"log10", math_log10}, + LROT_FUNCENTRY( log10, math_log10) #endif - {"log", math_log}, - {"max", math_max}, - {"min", math_min}, - {"modf", math_modf}, - {"pow", math_pow}, - {"rad", math_rad}, - {"random", math_random}, - {"randomseed", math_randomseed}, - {"sinh", math_sinh}, - {"sin", math_sin}, - {"sqrt", math_sqrt}, - {"tanh", math_tanh}, - {"tan", math_tan}, - {NULL, NULL} -}; - -const luaR_value_entry mathlib_vals[] = { - {"pi", PI}, - {"huge", HUGE_VAL}, - {NULL, 0} -}; + LROT_FUNCENTRY( log, math_log) + LROT_FUNCENTRY( max, math_max) + LROT_FUNCENTRY( min, math_min) + LROT_FUNCENTRY( modf, math_modf) + LROT_FUNCENTRY( pow, math_pow) + LROT_FUNCENTRY( rad, math_rad) + LROT_FUNCENTRY( random, math_random) + LROT_FUNCENTRY( randomseed, math_randomseed) + LROT_FUNCENTRY( sinh, math_sinh) + LROT_FUNCENTRY( sin, math_sin) + LROT_FUNCENTRY( sqrt, math_sqrt) + LROT_FUNCENTRY( tanh, math_tanh) + LROT_FUNCENTRY( tan, math_tan) + LROT_NUMENTRY( pi, PI) + LROT_NUMENTRY( huge,(lua_Number)HUGE_VAL) +LROT_END(mathlib, NULL, 0) + /* ** Open math library diff --git a/radio/src/thirdparty/Lua/src/lobject.h b/radio/src/thirdparty/Lua/src/lobject.h index ff421aeef82..d929809d109 100644 --- a/radio/src/thirdparty/Lua/src/lobject.h +++ b/radio/src/thirdparty/Lua/src/lobject.h @@ -55,6 +55,9 @@ #define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */ #define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */ +/* Variant tags for tables */ +#define LUA_TTBLRAM (LUA_TTABLE | (0 << 4)) /* RAM based Table */ +#define LUA_TTBLROF (LUA_TTABLE | (1 << 4)) /* RO Flash based ROTable */ /* Bit mark for collectable types */ #define BIT_ISCOLLECTABLE (1 << 6) @@ -133,11 +136,12 @@ typedef union Value Value; #define ttisnil(o) checktag((o), LUA_TNIL) #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) -#define ttisrotable(o) checktag((o), LUA_TROTABLE) #define ttisstring(o) checktype((o), LUA_TSTRING) #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) -#define ttistable(o) checktag((o), ctb(LUA_TTABLE)) +#define ttistable(o) checktype((o), LUA_TTABLE) +#define ttisrwtable(o) checktag((o), ctb(LUA_TTBLRAM)) +#define ttisrotable(o) checktag((o), ctb(LUA_TTBLROF)) #define ttisfunction(o) checktype(o, LUA_TFUNCTION) #define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION) #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) @@ -163,6 +167,8 @@ typedef union Value Value; #define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c) #define fvalue(o) check_exp(ttislcf(o), val_(o).f) #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) +#define rwhvalue(o) check_exp(ttisrwtable(o), gco2rwt(&val_(o).gc)) +#define rohvalue(o) check_exp(ttisrotable(o), gco2rot(val_(o).gc)) #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) /* a dead value may get the 'gc' field, but cannot access its contents */ @@ -196,9 +202,6 @@ typedef union Value Value; #define setpvalue(obj,x) \ { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); } -#define setrvalue(obj,x) \ - { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TROTABLE); } - #define setbvalue(obj,x) \ { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } @@ -233,8 +236,8 @@ typedef union Value Value; checkliveness(G(L),io); } #define sethvalue(L,obj,x) \ - { TValue *io=(obj); \ - val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \ + { TValue *io=(obj); Table *x_ = (x); \ + val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(x_->tt)); \ checkliveness(G(L),io); } #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) @@ -542,6 +545,20 @@ typedef union Closure { #define getproto(o) (clLvalue(o)->p) +/* +** Common Table fields for both table versions (like CommonHeader in +** macro form, to be included in table structure definitions). +** +** Note that the sethvalue() macro works much like the setsvalue() +** macro and handles the abstracted type. the hvalue(o) macro can be +** used to access CommonTable fields, but the rwhvalue(o) and +** rohvalue(o) value variants must be used if accessing variant-specfic +** fields +*/ + +#define CommonTable CommonHeader; \ + lu_byte flags; lu_byte lsizenode; struct Table *metatable; + /* ** Tables */ @@ -562,17 +579,29 @@ typedef struct Node { typedef struct Table { - CommonHeader; - lu_byte flags; /* 1<

>>>>>>>>>> + +#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)}, +#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA(x)}, +#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)}, +#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t)}, + +#define LROT_TABLE(rt) const ROTable rt ## _ROTable +#define LROT_ENTRYREF(rt) (rt ##_entries) +#define LROT_TABLEREF(rt) (&rt ##_ROTable) +#define LROT_BEGIN(rt,mt,f) extern LROT_TABLE(rt); \ + static ROTable_entry rt ## _entries[] = { +#define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \ + const ROTable rt ## _ROTable = { \ + (GCObject *)1, LUA_TTBLROF, LROT_MARKED, \ + cast(lu_byte, ~(f)), (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \ + cast(Table *, mt), cast(ROTable_entry *, rt ## _entries) }; +#define LROT_BREAK(rt) }; + +#define LROT_MASK(m) cast(lu_byte, 1< -#include "lua.h" -#include "lauxlib.h" -#include "lstring.h" -#include "lrotable.h" - -/* Utility function: find a key in a given table of functions */ -static luaR_result luaR_findfunctionkey(const luaL_Reg* pf, const char * key, TValue * found) { - if(!pf) - return 0; - - while(1) { - if (!pf->name) - break; - if (!strcmp(pf->name, key)) { - setfvalue(found, pf->func); - return 1; - } - pf++; - } - return 0; -} - -/* Utility function: find a key in a given table of constants */ -static luaR_result luaR_findconstantkey(const luaR_value_entry* pv, const char * key, TValue * found) { - if(!pv) - return 0; - - while(1) { - if (!pv->name) - break; - if (!strcmp(pv->name, key)) { - setnvalue(found, pv->value); - return 1; - } - pv++; - } - return 0; -} - -/* Utility function: find a key in a given table of strings */ -static luaR_result luaR_findstringkey(lua_State *L, const luaR_string_entry* ps, const char * key, TValue * found) { - if(!ps) - return 0; - - while(1) { - if (!ps->name) - break; - if (!strcmp(ps->name, key)) { - TString *ts = luaS_new(L, ps->string); - setsvalue(L, found, ts); - return 1; - } - ps++; - } - return 0; -} - -/* Find a global "read only table" in the constant lua_rotable array */ -luaR_result luaR_findglobal(lua_State *L, const char * name, TValue * val) { - unsigned i; - if (strlen(name) > LUA_MAX_ROTABLE_NAME) { - TRACE_LUA_INTERNALS("luaR_findglobal('%s') = NAME TOO LONG", name); - return 0; - } - for (i=0; lua_rotable[i].name; i++) { - void * table = (void *)(&lua_rotable[i]); - if (!strcmp(lua_rotable[i].name, name)) { - setrvalue(val, table); - TRACE_LUA_INTERNALS("luaR_findglobal('%s') = TABLE %p (%s)", name, table, lua_rotable[i].name); - return 1; - } - if (!strncmp(lua_rotable[i].name, "__", 2)) { - if (luaR_findentry(L, table, name, val)) { - TRACE_LUA_INTERNALS("luaR_findglobal('%s') = FOUND in table '%s'", name, lua_rotable[i].name); - return 1; - } - } - } - TRACE_LUA_INTERNALS("luaR_findglobal() '%s' = NOT FOUND", name); - return 0; -} - - -luaR_result luaR_findentry(lua_State *L, void *data, const char * key, TValue * val) { - luaR_table * table = (luaR_table *)data; - /* First look at the functions */ - if (luaR_findfunctionkey(table->pfuncs, key, val)) { - TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = FUNCTION %p", table, table->name, key, lfvalue(val)); - return 1; - } - else if (luaR_findconstantkey(table->pvalues, key, val)) { - /* Then at the values */ - TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = NUMBER %g", table, table->name, key, nvalue(val)); - return 1; - } - else if (luaR_findstringkey(L, table->pstrings, key, val)) { - /* Then at the strings */ - TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = STRING %s", table, table->name, key, svalue(val)); - return 1; - } - TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = NOT FOUND", table, table->name, key); - return 0; -} diff --git a/radio/src/thirdparty/Lua/src/lrotable.h b/radio/src/thirdparty/Lua/src/lrotable.h deleted file mode 100644 index 788d426de3f..00000000000 --- a/radio/src/thirdparty/Lua/src/lrotable.h +++ /dev/null @@ -1,46 +0,0 @@ -// Read-only tables for Lua - -#ifndef lrotable_h -#define lrotable_h - -#include "lua.h" -#include "llimits.h" -#include "lauxlib.h" -#include "lobject.h" - -typedef uint8_t luaR_result; - -// A number entry in the read only table -typedef struct -{ - const char *name; - lua_Number value; -} luaR_value_entry; - -// A string entry in the read only table -typedef struct -{ - const char *name; - const char *string; -} luaR_string_entry; - -extern const luaR_value_entry baselib_vals[]; -extern const luaR_value_entry mathlib_vals[]; -extern const luaR_value_entry opentxConstants[]; -extern const luaR_string_entry edgetxStrings[]; - -// A mapping between table name and its entries -typedef struct -{ - const char *name; - const luaL_Reg *pfuncs; - const luaR_value_entry *pvalues; - const luaR_string_entry *pstrings; -} luaR_table; - -extern const luaR_table lua_rotable[]; - -luaR_result luaR_findglobal(lua_State *L, const char * name, TValue * val); -luaR_result luaR_findentry(lua_State *L, void * data, const char * key, TValue * val); - -#endif diff --git a/radio/src/thirdparty/Lua/src/lstate.c b/radio/src/thirdparty/Lua/src/lstate.c index 207a106d5ba..d9085d63e34 100644 --- a/radio/src/thirdparty/Lua/src/lstate.c +++ b/radio/src/thirdparty/Lua/src/lstate.c @@ -218,6 +218,8 @@ static void preinit_state (lua_State *L, global_State *g) { } +static lua_State *L0 = NULL; + static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ @@ -225,6 +227,10 @@ static void close_state (lua_State *L) { luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); luaZ_freebuffer(L, &g->buff); freestack(L); + if (L == L0) { + (*g->frealloc)(g->ud, g->cache, KEYCACHE_N * sizeof(KeyCacheLine), 0); + L0 = NULL; /* so reopening state initialises properly */ + } lua_assert(gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ } @@ -258,6 +264,9 @@ void luaE_freethread (lua_State *L, lua_State *L1) { luaM_free(L, l); } +LUAI_FUNC KeyCache *luaE_getcache (int lineno) { + return &G(L0)->cache[lineno][0]; +} LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { int i; @@ -300,6 +309,18 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->gcpause = LUAI_GCPAUSE; g->gcmajorinc = LUAI_GCMAJOR; g->gcstepmul = LUAI_GCMUL; +#ifdef LUA_ENABLE_TEST + if (L0) { /* This is a second state */ + g->cache=G(L0)->cache; + } else { +#endif + L0 = L; + g->cache = cast(KeyCacheLine *, + (*f)(ud, NULL, 0, KEYCACHE_N * sizeof(KeyCacheLine))); + memset(g->cache, 0, KEYCACHE_N * sizeof(KeyCacheLine)); +#ifdef LUA_ENABLE_TEST + } +#endif for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { /* memory allocation error: free partial state */ diff --git a/radio/src/thirdparty/Lua/src/lstate.h b/radio/src/thirdparty/Lua/src/lstate.h index c8a31f5c0b8..b2689e69aa1 100644 --- a/radio/src/thirdparty/Lua/src/lstate.h +++ b/radio/src/thirdparty/Lua/src/lstate.h @@ -105,10 +105,16 @@ typedef struct CallInfo { #define isLua(ci) ((ci)->callstatus & CIST_LUA) +/* +** KeyCache used for resolution of ROTable entries and Cstrings +*/ +typedef lu_int32 KeyCache; +typedef KeyCache KeyCacheLine[KEYCACHE_M]; /* ** `global state', shared by all threads of this state */ + typedef struct global_State { lua_Alloc frealloc; /* function to reallocate memory */ void *ud; /* auxiliary data to `frealloc' */ @@ -145,6 +151,7 @@ typedef struct global_State { TString *memerrmsg; /* memory-error message */ TString *tmname[TM_N]; /* array with tag-method names */ struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ + KeyCacheLine *cache; /* cache for strings in API */ } global_State; @@ -188,6 +195,7 @@ union GCObject { union Udata u; union Closure cl; struct Table h; + struct ROTable roh; struct Proto p; struct UpVal uv; struct lua_State th; /* thread */ @@ -206,7 +214,10 @@ union GCObject { #define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c)) #define gco2cl(o) \ check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl)) -#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2t(o) \ + check_exp(novariant((o)->gch.tt) == LUA_TTABLE, &((o)->h)) +#define gco2rwt(o) check_exp((o)->gch.tt == LUA_TTBLRAM, &((o)->h)) +#define gco2rot(o) check_exp((o)->gch.tt == LUA_TTBLROF, &((o)->roh)) #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) @@ -222,7 +233,7 @@ LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); LUAI_FUNC void luaE_freeCI (lua_State *L); - +LUAI_FUNC KeyCache *luaE_getcache (int cl); #endif diff --git a/radio/src/thirdparty/Lua/src/lstrlib.c b/radio/src/thirdparty/Lua/src/lstrlib.c index d6c70fb457f..1b14b12dd81 100644 --- a/radio/src/thirdparty/Lua/src/lstrlib.c +++ b/radio/src/thirdparty/Lua/src/lstrlib.c @@ -4,6 +4,8 @@ ** See Copyright Notice in lua.h */ +#define lstrlib_c +#define LUA_LIB #include #include @@ -11,8 +13,6 @@ #include #include -#define lstrlib_c - #include "lua.h" #include "lauxlib.h" @@ -975,44 +975,32 @@ static int str_format (lua_State *L) { /* }====================================================== */ - -const luaL_Reg strlib[] = { - {"byte", str_byte}, - {"char", str_char}, - {"dump", str_dump}, - {"find", str_find}, - {"format", str_format}, - {"gmatch", gmatch}, - {"gsub", str_gsub}, - {"len", str_len}, - {"lower", str_lower}, - {"match", str_match}, - {"rep", str_rep}, - {"reverse", str_reverse}, - {"sub", str_sub}, - {"upper", str_upper}, - {NULL, NULL} -}; - -#if 0 -static void createmetatable (lua_State *L) { - lua_createtable(L, 0, 1); /* table to be metatable for strings */ - lua_pushliteral(L, ""); /* dummy string */ - lua_pushvalue(L, -2); /* copy table */ - lua_setmetatable(L, -2); /* set table as metatable for strings */ - lua_pop(L, 1); /* pop dummy string */ - lua_pushvalue(L, -2); /* get string library */ - lua_setfield(L, -2, "__index"); /* metatable.__index = string */ - lua_pop(L, 1); /* pop metatable */ -} +LROT_BEGIN(strlib, NULL, LROT_MASK_INDEX) + LROT_TABENTRY( __index, strlib ) + LROT_FUNCENTRY( byte, str_byte ) + LROT_FUNCENTRY( char, str_char ) + LROT_FUNCENTRY( dump, str_dump ) + LROT_FUNCENTRY( find, str_find ) + LROT_FUNCENTRY( format, str_format ) + LROT_FUNCENTRY( gmatch, gmatch ) + LROT_FUNCENTRY( gsub, str_gsub ) + LROT_FUNCENTRY( len, str_len ) + LROT_FUNCENTRY( lower, str_lower ) + LROT_FUNCENTRY( match, str_match ) + LROT_FUNCENTRY( rep, str_rep ) + LROT_FUNCENTRY( reverse, str_reverse ) + LROT_FUNCENTRY( sub, str_sub ) + LROT_FUNCENTRY( upper, str_upper ) +LROT_END(strlib, NULL, LROT_MASK_INDEX) /* ** Open string library */ LUAMOD_API int luaopen_string (lua_State *L) { - luaL_newlib(L, strlib); - createmetatable(L); - return 1; + lua_pushliteral(L, ""); /* dummy string */ + lua_pushrotable(L, LROT_TABLEREF(strlib)); + lua_setmetatable(L, -2); /* set table as metatable for strings */ + lua_pop(L, 1); /* pop dummy string */ + return 0; } -#endif diff --git a/radio/src/thirdparty/Lua/src/ltable.c b/radio/src/thirdparty/Lua/src/ltable.c index c9fd21d4bd3..a2893bbafb3 100644 --- a/radio/src/thirdparty/Lua/src/ltable.c +++ b/radio/src/thirdparty/Lua/src/ltable.c @@ -165,9 +165,15 @@ static int findindex (lua_State *L, Table *t, StkId key) { } } +static void rotable_next(lua_State *L, ROTable *t, TValue *key, TValue *val); int luaH_next (lua_State *L, Table *t, StkId key) { - int i = findindex(L, t, key); /* find original element */ + int i; + if (isrotable(t)) { + rotable_next(L, (ROTable *) t, key, key+1); + return ttisnil(key) ? 0 : 1; + } + i = findindex(L, t, key); /* find original element */ for (i++; i < t->sizearray; i++) { /* try first array part */ if (!ttisnil(&t->array[i])) { /* a non-nil value? */ setnvalue(key, cast_num(i+1)); @@ -401,6 +407,7 @@ static Node *getfreepos (Table *t) { */ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { Node *mp; + if(!isrwtable(t)) luaG_runerror(L, "table is Readonly"); if (ttisnil(key)) luaG_runerror(L, "table index is nil"); else if (ttisnumber(key) && luai_numisnan(L, nvalue(key))) luaG_runerror(L, "table index is NaN"); @@ -441,6 +448,8 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { ** search function for integers */ const TValue *luaH_getint (Table *t, int key) { + if (isrotable(t)) + return luaO_nilobject; /* (1 <= key && key <= t->sizearray) */ if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) return &t->array[key-1]; @@ -460,8 +469,14 @@ const TValue *luaH_getint (Table *t, int key) { /* ** search function for short strings */ + +static const TValue* rotable_findentry(ROTable *rotable, TString *key, unsigned *ppos); + const TValue *luaH_getstr (Table *t, TString *key) { - Node *n = hashstr(t, key); + Node *n; + if (isrotable(t)) + return rotable_findentry((ROTable*) t, key, NULL); + n = hashstr(t, key); lua_assert(key->tsv.tt == LUA_TSHRSTR); do { /* check whether `key' is somewhere in the chain */ if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key)) @@ -488,7 +503,9 @@ const TValue *luaH_get (Table *t, const TValue *key) { /* else go through */ } default: { - Node *n = mainposition(t, key); + Node *n; + if (isrotable(t)) return luaO_nilobject; + n = mainposition(t, key); do { /* check whether `key' is somewhere in the chain */ if (luaV_rawequalobj(gkey(n), key)) return gval(n); /* that's it */ @@ -505,7 +522,10 @@ const TValue *luaH_get (Table *t, const TValue *key) { ** barrier and invalidate the TM cache. */ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { - const TValue *p = luaH_get(t, key); + const TValue *p; + if (isrotable(t)) + luaG_runerror(L, "table is readonly"); + p = luaH_get(t, key); if (p != luaO_nilobject) return cast(TValue *, p); else return luaH_newkey(L, t, key); @@ -513,7 +533,10 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { void luaH_setint (lua_State *L, Table *t, int key, TValue *value) { - const TValue *p = luaH_getint(t, key); + const TValue *p; + if (isrotable(t)) + luaG_runerror(L, "table is readonly"); + p = luaH_getint(t, key); TValue *cell; if (p != luaO_nilobject) cell = cast(TValue *, p); @@ -572,6 +595,134 @@ int luaH_getn (Table *t) { else return unbound_search(t, j); } +int luaH_isdummy (const Node *n) { return isdummy(n); } + + +/* +** All keyed ROTable access passes through rotable_findentry(). ROTables +** are simply a list of pairs. +** +** The global KeyCache is used to avoid a relatively expensive Flash memory +** vector scan. A simple hash on the key's TString addr and the ROTable +** addr selects the cache line. The line's slots are then scanned for a +** hit. +** +** Unlike the standard hash which uses a prime line count therefore requires +** the use of modulus operation which is expensive on an IoT processor +** without H/W divide. This hash is power of 2 based which might not be quite +** so uniform but can be calculated without using H/W-based instructions. +** +** If a match is found and the table addresses match, then this entry is +** probed first. In practice the hit-rate here is over 99% so the code +** rarely fails back to doing the linear scan in ROM. +** Note that this hash does a couple of prime multiples and a modulus 2^X +** with is all evaluated in H/W, and adequately randomizes the lookup. +*/ +#define HASH(a,b) ((((29*(size_t)(a)) ^ (37*((b)->tsv.hash)))>>4)&(KEYCACHE_N-1)) +#define NDX_SHFT 24 +#define ADDR_MASK (((size_t) 1<<24)-1) + +/* + * Find a string key entry in a rotable and return it. + */ +static const TValue* rotable_findentry(ROTable *t, TString *key, unsigned *ppos) { + const ROTable_entry *e = cast(const ROTable_entry *, t->entry); + const int tl = t->lsizenode; + const char *strkey = getstr(key); + const int hash = HASH(t, key); + KeyCache *cl = luaE_getcache(hash); + int i, j = 1, l; + + if (!e || key->tsv.tt != LUA_TSHRSTR) + return luaO_nilobject; + + l = key->tsv.len; + /* scan the ROTable key cache and return if hit found */ + for (i = 0; i < KEYCACHE_M; i++) { + lu_int32 cl_ndx = cl[i] >> NDX_SHFT; + if ((((size_t)t - cl[i]) & ADDR_MASK) == 0 && cl_ndx < tl && + strcmp(e[cl_ndx].key, strkey) == 0) { + if (ppos) + *ppos = cl_ndx; + return &e[cl_ndx].value; + } + } + /* + * In practice most table scans are from a table miss due to the key cache + * short-circuiting almost all table hits. ROTable keys can be unsorted + * because of legacy compatibility, so the search must use a sequential + * equality match. + * + * The masked name4 comparison is a safe 4-byte comparison for all supported + * NodeMCU hosts and targets; It generate fast efficient access that avoids + * unaligned exceptions and costly strcmp() except for a last hit validation. + * However, this is ENDIAN SENSITIVE which is validate during initialisation. + * + * The majority of search misses are for metavalues (keys starting with __), + * so all metavalues if any must be at the front of each entry list. + */ + lu_int32 name4 = *(lu_int32 *)strkey; + lu_int32 mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); + lua_assert(*(int*)"abcd" == 0x64636261); +#define eq4(s) (((*(lu_int32 *)s ^ name4) & mask4) == 0) +#define ismeta(s) ((*(lu_int32 *)s & 0xffff) == *(lu_int32 *)"__\0") + + if (ismeta(&name4)) { + for(i = 0; i < tl && ismeta(e[i].key); i++) { + if (eq4(e[i].key) && !strcmp(e[i].key, strkey)) { + j = 0; break; + } + } + } else { + for(i = 0; i < tl; i++) { + if (eq4(e[i].key) && !strcmp(e[i].key, strkey)) { + j = 0; break; + } + } + } + if (j) + return luaO_nilobject; + if (ppos) + *ppos = i; + /* In the case of a hit, update the lookaside cache */ + for (j = KEYCACHE_M-1; j>0; j--) + cl[j] = cl[j-1]; + cl[0] = ((size_t)t & ADDR_MASK) + ((lu_int32)i << NDX_SHFT); + return &e[i].value; +} + + +static void rotable_next_helper(lua_State *L, ROTable *t, int pos, + TValue *key, TValue *val) { + const ROTable_entry *e = cast(const ROTable_entry *, t->entry); + if (pos < t->lsizenode) { + /* Found an entry */ + setsvalue(L, key, luaS_new(L, e[pos].key)); + setobj2s(L, val, &e[pos].value); + } else { + setnilvalue(key); + setnilvalue(val); + } +} + + +/* next (used for iteration) */ +static void rotable_next(lua_State *L, ROTable *t, TValue *key, TValue *val) { + unsigned keypos = t->lsizenode; + + /* Special case: if key is nil, return the first element of the rotable */ + if (ttisnil(key)) + rotable_next_helper(L, t, 0, key, val); + else if (ttisstring(key)) { + /* Find the previous key again */ + if (ttisstring(key)) { + rotable_findentry(t, rawtsvalue(key), &keypos); + } + /* Advance to next key */ + rotable_next_helper(L, t, ++keypos, key, val); + } +} + #if defined(LUA_DEBUG) @@ -580,6 +731,4 @@ Node *luaH_mainposition (const Table *t, const TValue *key) { return mainposition(t, key); } -int luaH_isdummy (Node *n) { return isdummy(n); } - #endif diff --git a/radio/src/thirdparty/Lua/src/ltable.h b/radio/src/thirdparty/Lua/src/ltable.h index 2f6f5c2dc85..35dbb083702 100644 --- a/radio/src/thirdparty/Lua/src/ltable.h +++ b/radio/src/thirdparty/Lua/src/ltable.h @@ -18,6 +18,11 @@ #define invalidateTMcache(t) ((t)->flags = 0) +/* test Table to determine if it is a RW or RO table */ +#define isrotable(t) ((t)->tt==LUA_TTBLROF) +#define isrwtable(t) ((t)->tt==LUA_TTBLRAM) + + LUAI_FUNC const TValue *luaH_getint (Table *t, int key); LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); diff --git a/radio/src/thirdparty/Lua/src/ltm.c b/radio/src/thirdparty/Lua/src/ltm.c index d738b083481..71ee27af1e7 100644 --- a/radio/src/thirdparty/Lua/src/ltm.c +++ b/radio/src/thirdparty/Lua/src/ltm.c @@ -23,7 +23,7 @@ static const char udatatypename[] = "userdata"; LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { "no value", - "nil", "boolean", "rotable", udatatypename, "number", + "nil", "boolean", udatatypename, "number", "string", "table", "function", udatatypename, "thread", "proto", "upval" /* these last two cases are used for tests only */ }; diff --git a/radio/src/thirdparty/Lua/src/lua.h b/radio/src/thirdparty/Lua/src/lua.h index 967bb6d3b2f..33e75d3cc20 100644 --- a/radio/src/thirdparty/Lua/src/lua.h +++ b/radio/src/thirdparty/Lua/src/lua.h @@ -77,16 +77,15 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); #define LUA_TNIL 0 #define LUA_TBOOLEAN 1 -#define LUA_TROTABLE 2 -#define LUA_TLIGHTUSERDATA 3 -#define LUA_TNUMBER 4 -#define LUA_TSTRING 5 -#define LUA_TTABLE 6 -#define LUA_TFUNCTION 7 -#define LUA_TUSERDATA 8 -#define LUA_TTHREAD 9 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 -#define LUA_NUMTAGS 10 +#define LUA_NUMTAGS 9 @@ -215,7 +214,6 @@ LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); LUA_API void (lua_pushboolean) (lua_State *L, int b); LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); -LUA_API void (lua_pushrotable) (lua_State *L, void *p); LUA_API int (lua_pushthread) (lua_State *L); @@ -429,6 +427,15 @@ struct lua_Debug { /* }====================================================================== */ +/* ROTable extensions to the standard API */ + +typedef struct ROTable ROTable; +typedef struct ROTable_entry ROTable_entry; + +LUA_API void (lua_pushrotable) (lua_State *L, const ROTable *p); +LUA_API void (lua_createrotable) (lua_State *L, ROTable *t, const ROTable_entry *e, ROTable *mt); + +/* }====================================================================== */ /****************************************************************************** * Copyright (C) 1994-2013 Lua.org, PUC-Rio. diff --git a/radio/src/thirdparty/Lua/src/luaconf.h b/radio/src/thirdparty/Lua/src/luaconf.h index 00258505c4d..a924c473d3f 100644 --- a/radio/src/thirdparty/Lua/src/luaconf.h +++ b/radio/src/thirdparty/Lua/src/luaconf.h @@ -15,7 +15,8 @@ #define USE_FATFS #endif -#define LUA_ANSI // force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826) +// force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826) +#define LUA_ANSI /* ** ================================================================== @@ -398,8 +399,8 @@ ** =================================================================== */ -#define LUA_NUMBER_DOUBLE -#define LUA_NUMBER double +#define LUA_NUMBER_FLOAT +#define LUA_NUMBER float /* @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @@ -414,8 +415,8 @@ @@ lua_number2str converts a number to a string. @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. */ -#define LUA_NUMBER_SCAN "%lf" -#define LUA_NUMBER_FMT "%.14g" +#define LUA_NUMBER_SCAN "%f" +#define LUA_NUMBER_FMT "%.7g" #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ @@ -434,10 +435,10 @@ ** systems, you can leave 'lua_strx2number' undefined and Lua will ** provide its own implementation. */ -#define lua_str2number(s,p) strtod((s), (p)) +#define lua_str2number(s,p) strtof((s), (p)) #if defined(LUA_USE_STRTODHEX) -#define lua_strx2number(s,p) strtod((s), (p)) +#define lua_strx2number(s,p) lua_str2number(s,p) #endif @@ -560,6 +561,4 @@ ** without modifying the main part of the file. */ -#define LUA_MAX_ROTABLE_NAME 32 - #endif diff --git a/radio/src/thirdparty/Lua/src/lvm.c b/radio/src/thirdparty/Lua/src/lvm.c index 442e5d44dde..ac287945027 100644 --- a/radio/src/thirdparty/Lua/src/lvm.c +++ b/radio/src/thirdparty/Lua/src/lvm.c @@ -25,7 +25,7 @@ #include "ltable.h" #include "ltm.h" #include "lvm.h" -#include "lrotable.h" + /* limit for table tag-method chains (to avoid loops) */ @@ -106,27 +106,9 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1, } } -static void lua_getcstr(char *dest, const TString *src, size_t maxsize) { - if (src->tsv.len+1 > maxsize) - dest[0] = '\0'; - else { - memcpy(dest, getstr(src), src->tsv.len); - dest[src->tsv.len] = '\0'; - } -} void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; - if (ttisrotable(t)) { - setnilvalue(val); - if (ttisstring(key)) { - char keyname[LUA_MAX_ROTABLE_NAME + 1]; - lua_getcstr(keyname, rawtsvalue(key), LUA_MAX_ROTABLE_NAME); - TRACE_LUA_INTERNALS("luaV_gettable(%s)", keyname); - luaR_findentry(L, rvalue(t), keyname, val); - } - return; - } for (loop = 0; loop < MAXTAGLOOP; loop++) { const TValue *tm; if (ttistable(t)) { /* `t' is a table? */ @@ -139,9 +121,8 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { } /* else will try the tag method */ } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) luaG_typeerror(L, t, "index"); - } if (ttisfunction(tm)) { callTM(L, tm, t, key, val, 1); return; @@ -225,24 +206,22 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, } +/* +** Compare two strings 'ls' x 'rs', returning an integer smaller-equal- +** -larger than zero if 'ls' is smaller-equal-larger than 'rs'. +** Stripped down version for NodeMCU without locales support +*/ static int l_strcmp (const TString *ls, const TString *rs) { const char *l = getstr(ls); - size_t ll = ls->tsv.len; const char *r = getstr(rs); - size_t lr = rs->tsv.len; - for (;;) { - int temp = strcoll(l, r); - if (temp != 0) return temp; - else { /* strings are equal up to a `\0' */ - size_t len = strlen(l); /* index of first `\0' in both strings */ - if (len == lr) /* r is finished? */ - return (len == ll) ? 0 : 1; - else if (len == ll) /* l is finished? */ - return -1; /* l is smaller than r (because r is not finished) */ - /* both strings longer than `len'; go on comparing (after the `\0') */ - len++; - l += len; ll -= len; r += len; lr -= len; - } + if (l == r) { + return 0; + } else { + size_t ll = ls->tsv.len; + size_t lr = rs->tsv.len; + size_t lm = llmetatable, uvalue(t2)->metatable, TM_EQ); break; /* will try TM */ } - case LUA_TTABLE: { + case LUA_TTBLRAM: + case LUA_TTBLROF: { if (hvalue(t1) == hvalue(t2)) return 1; else if (L == NULL) return 0; tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); @@ -619,21 +597,11 @@ void luaV_execute (lua_State *L) { case OP_GETTABUP: { int b = GETARG_B(i); - if (ttisstring(RKC(i))) { - char keyname[LUA_MAX_ROTABLE_NAME + 1]; - lua_getcstr(keyname, rawtsvalue(RKC(i)), LUA_MAX_ROTABLE_NAME); - TRACE_LUA_INTERNALS("luaV_execute(OP_GETTABUP, %s)", keyname); - if (luaR_findglobal(L, keyname, ra)) { - break; - } - } - TRACE_LUA_INTERNALS("luaV_execute(OP_GETTABUP, %d) OLD WAY", b); Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra)); } break; case OP_GETTABLE: - /* First try to look for a rotable with this name */ Protect(luaV_gettable(L, RB(i), RKC(i), ra)); break;