feat(lua): Port of NodeMCU Lua53 read-only tables (#2994)

* 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.

* feat(lua): port of NodeMCU Lua53 read-only tables

# Conflicts:
#	radio/src/lua/CMakeLists.txt
#	radio/src/lua/api_general.cpp

* fix(nv14): missing SDRAM definition

* fix: l_mathop

* fix: use float functions in drawPower()

* fix: ltable resize

* fix: correct name is "bit32"

* fix: first Lua context must be closed last

As the lookup cache is attached to that one

* Revert to Lua using double

* Ensure byte-code compatibility

* Fix possible compatibility issue with `lua_typename`/`luaL_typename`

* Fix Bitmap symbol table

* Re-add table lib for COLORLCD
This commit is contained in:
Raphael Coeffic
2023-02-09 20:29:56 +10:00
committed by GitHub
parent 72193eda82
commit be3f8d74a8
43 changed files with 1387 additions and 2211 deletions
+1 -73
View File
@@ -107,7 +107,6 @@ endif()
add_subdirectory(bitmaps)
add_subdirectory(fonts)
add_subdirectory(lua)
if(NOT PCB STREQUAL 9XRPRO)
option(DBLKEYS "Double Keys" ON)
@@ -177,78 +176,7 @@ if(RTC_BACKUP_RAM)
endif()
if(LUA)
add_definitions(-DLUA)
if(LUA_COMPILER)
add_definitions(-DLUA_COMPILER)
endif()
if(LUA_ALLOCATOR_TRACER AND DEBUG)
add_definitions(-DLUA_ALLOCATOR_TRACER)
endif()
if(NOT "${LUA_SCRIPT_LOAD_MODE}" STREQUAL "")
add_definitions(-DLUA_SCRIPT_LOAD_MODE="${LUA_SCRIPT_LOAD_MODE}")
endif()
include_directories(${LUA_DIR})
set(RADIO_DEPENDENCIES ${RADIO_DEPENDENCIES} ${LUA_EXPORT})
if(LUA_MIXER)
add_definitions(-DLUA_MODEL_SCRIPTS)
endif()
# TODO: LUA CMAKE
set(SRC ${SRC}
lua/interface.cpp
lua/api_general.cpp
lua/api_model.cpp
lua/api_filesystem.cpp
lua/lua_event.cpp
)
if(GUI_DIR STREQUAL colorlcd)
set(SRC ${SRC} lua/api_colorlcd.cpp lua/widgets.cpp)
else()
set(SRC ${SRC} lua/api_stdlcd.cpp)
endif()
set(LUA_SRC
lapi.c
lcode.c
lctype.c
ldebug.c
ldo.c
ldump.c
lfunc.c
lgc.c
llex.c
lmem.c
lobject.c
lopcodes.c
lparser.c
lstate.c
lstring.c
ltable.c
lrotable.c
ltm.c
lundump.c
lvm.c
lzio.c
linit.c
lbaselib.c
lmathlib.c
lbitlib.c
loadlib.c
lauxlib.c
ltablib.c
lcorolib.c
liolib.c
lstrlib.c
)
foreach(FILE ${LUA_SRC})
set(SRC ${SRC} ${LUA_DIR}/${FILE})
endforeach()
if(MSVC)
# silence lots of warnings regarding "insecure" use of functions (sprintf, strcpy, etc) from Lua code
set(WARNING_FLAGS "${WARNING_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
endif()
include(lua/CMakeLists.txt)
endif()
if (LUA_MIXER AND NOT LUA)
@@ -325,18 +325,18 @@ bool isSwitchAvailableInCustomFunctions(int swtch)
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att)
{
float power_W_PREC1 = pow(10.0, (dBm - 30.0) / 10.0) * 10;
float power_W_PREC1 = powf(10.0, (dBm - 30.0) / 10.0) * 10;
if (dBm >= 30) {
lcdDrawNumber(x, y, power_W_PREC1, PREC1 | att);
lcdDrawText(lcdNextPos, y, "W", att);
}
else if (dBm < 10) {
uint16_t power_MW_PREC1 = round(power_W_PREC1 * 1000);
uint16_t power_MW_PREC1 = roundf(power_W_PREC1 * 1000);
lcdDrawNumber(x, y, power_MW_PREC1, PREC1 | att);
lcdDrawText(lcdNextPos, y, "mW", att);
}
else {
uint16_t power_MW = round(power_W_PREC1 * 100);
uint16_t power_MW = roundf(power_W_PREC1 * 100);
if (power_MW >= 50) {
power_MW = (power_MW / 5) * 5;
lcdDrawNumber(x, y, power_MW, att);
+73
View File
@@ -41,3 +41,76 @@ if(PYTHONINTERP_FOUND)
add_lua_export_target(t16 ${LUA_INCLUDES} -DPCBHORUS -DPCBX10 -DRADIO_T16)
add_lua_export_target(nv14 ${LUA_INCLUDES} -I${RADIO_SRC_DIR}/targets/nv14 -DPCBNV14)
endif()
add_definitions(-DLUA)
if(LUA_COMPILER)
add_definitions(-DLUA_COMPILER)
endif()
if(LUA_ALLOCATOR_TRACER AND DEBUG)
add_definitions(-DLUA_ALLOCATOR_TRACER)
endif()
if(NOT "${LUA_SCRIPT_LOAD_MODE}" STREQUAL "")
add_definitions(-DLUA_SCRIPT_LOAD_MODE="${LUA_SCRIPT_LOAD_MODE}")
endif()
include_directories(${LUA_DIR})
set(RADIO_DEPENDENCIES ${RADIO_DEPENDENCIES} ${LUA_EXPORT})
if(LUA_MIXER)
add_definitions(-DLUA_MODEL_SCRIPTS)
endif()
set(SRC ${SRC}
lua/interface.cpp
lua/api_general.cpp
lua/api_model.cpp
lua/api_filesystem.cpp
lua/lua_event.cpp
)
if(GUI_DIR STREQUAL colorlcd)
set(SRC ${SRC} lua/api_colorlcd.cpp lua/widgets.cpp)
else()
set(SRC ${SRC} lua/api_stdlcd.cpp)
endif()
set(LUA_SRC
lapi.c
lcode.c
lctype.c
ldebug.c
ldo.c
ldump.c
lfunc.c
lgc.c
llex.c
lmem.c
lobject.c
lopcodes.c
lparser.c
lstate.c
lstring.c
ltable.c
ltm.c
lundump.c
lvm.c
lzio.c
linit.c
lbaselib.c
lmathlib.c
lbitlib.c
loadlib.c
lauxlib.c
ltablib.c
lcorolib.c
liolib.c
lstrlib.c
)
foreach(FILE ${LUA_SRC})
set(SRC ${SRC} ${LUA_DIR}/${FILE})
endforeach()
+70 -58
View File
@@ -19,13 +19,24 @@
* GNU General Public License for more details.
*/
#define LUA_LIB
#include <cctype>
#include <cstdio>
#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,59 @@ 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_FUNCENTRY( getSize, luaGetBitmapSize )
LROT_FUNCENTRY( resize, luaBitmapResize )
LROT_FUNCENTRY( toMask, luaBitmapTo8bitMask )
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;
}
}
+2 -23
View File
@@ -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));
+20 -14
View File
@@ -19,10 +19,11 @@
* GNU General Public License for more details.
*/
#define LUA_LIB
#include <cstdio>
#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;
}
}
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;
}
}
+4 -4
View File
@@ -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);
#define DIR_METATABLE "DIR*"
EXTERN_C(LUALIB_API int luaopen_etxdir(lua_State* L));
+408 -409
View File
@@ -19,6 +19,8 @@
* GNU General Public License for more details.
*/
#define LUA_LIB
#include <ctype.h>
#include <stdio.h>
#include "opentx.h"
@@ -34,51 +36,51 @@
#endif
#if defined(PCBX12S)
#include "lua/lua_exports_x12s.inc" // this line must be after lua headers
#include "lua_exports_x12s.inc" // this line must be after lua headers
#elif defined(RADIO_FAMILY_T16)
#include "lua/lua_exports_t16.inc"
#include "lua_exports_t16.inc"
#elif defined(PCBX10)
#include "lua/lua_exports_x10.inc"
#include "lua_exports_x10.inc"
#elif defined(PCBX9E)
#include "lua/lua_exports_x9e.inc"
#include "lua_exports_x9e.inc"
#elif defined(RADIO_X7ACCESS)
#include "lua/lua_exports_x7access.inc"
#include "lua_exports_x7access.inc"
#elif defined(RADIO_X7)
#include "lua/lua_exports_x7.inc"
#include "lua_exports_x7.inc"
#elif defined(RADIO_T12)
#include "lua/lua_exports_t12.inc"
#include "lua_exports_t12.inc"
#elif defined(RADIO_TLITE)
#include "lua/lua_exports_tlite.inc"
#include "lua_exports_tlite.inc"
#elif defined(RADIO_TPRO)
#include "lua/lua_exports_tpro.inc"
#include "lua_exports_tpro.inc"
#elif defined(RADIO_TX12)
#include "lua/lua_exports_tx12.inc"
#include "lua_exports_tx12.inc"
#elif defined(RADIO_TX12MK2)
#include "lua/lua_exports_tx12mk2.inc"
#include "lua_exports_tx12mk2.inc"
#elif defined(RADIO_LR3PRO)
#include "lua/lua_exports_lr3pro.inc"
#include "lua_exports_lr3pro.inc"
#elif defined(RADIO_BOXER)
#include "lua/lua_exports_boxer.inc"
#include "lua_exports_boxer.inc"
#elif defined(RADIO_ZORRO)
#include "lua/lua_exports_zorro.inc"
#include "lua_exports_zorro.inc"
#elif defined(RADIO_T8)
#include "lua/lua_exports_t8.inc"
#include "lua_exports_t8.inc"
#elif defined(RADIO_COMMANDO8)
#include "lua/lua_exports_commando8.inc"
#include "lua_exports_commando8.inc"
#elif defined(PCBX9LITES)
#include "lua/lua_exports_x9lites.inc"
#include "lua_exports_x9lites.inc"
#elif defined(PCBX9LITE)
#include "lua/lua_exports_x9lite.inc"
#include "lua_exports_x9lite.inc"
#elif defined(PCBXLITES)
#include "lua/lua_exports_xlites.inc"
#include "lua_exports_xlites.inc"
#elif defined(PCBXLITE)
#include "lua/lua_exports_xlite.inc"
#include "lua_exports_xlite.inc"
#elif defined(RADIO_X9DP2019)
#include "lua/lua_exports_x9d+2019.inc"
#include "lua_exports_x9d+2019.inc"
#elif defined(PCBTARANIS)
#include "lua/lua_exports_x9d.inc"
#include "lua_exports_x9d.inc"
#elif defined(PCBNV14)
#include "lua/lua_exports_nv14.inc"
#include "lua_exports_nv14.inc"
#endif
#include "telemetry/frsky.h"
@@ -105,12 +107,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};
@@ -2628,502 +2624,505 @@ 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 */
};
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)
const luaR_value_entry opentxConstants[] = {
{ "FULLSCALE", RESX },
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_Rud },
{ "MIXSRC_Ele", MIXSRC_Ele },
{ "MIXSRC_Thr", MIXSRC_Thr },
{ "MIXSRC_Ail", MIXSRC_Ail },
{ "MIXSRC_SA", MIXSRC_SA },
{ "MIXSRC_SB", MIXSRC_SB },
{ "MIXSRC_SC", MIXSRC_SC },
{ "MIXSRC_SD", MIXSRC_SD },
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 )
LROT_NUMENTRY( MIXSRC_Rud, MIXSRC_Rud )
LROT_NUMENTRY( MIXSRC_Ele, MIXSRC_Ele )
LROT_NUMENTRY( MIXSRC_Thr, MIXSRC_Thr )
LROT_NUMENTRY( MIXSRC_Ail, MIXSRC_Ail )
LROT_NUMENTRY( MIXSRC_SA, MIXSRC_SA )
LROT_NUMENTRY( MIXSRC_SB, MIXSRC_SB )
LROT_NUMENTRY( MIXSRC_SC, MIXSRC_SC )
LROT_NUMENTRY( MIXSRC_SD, MIXSRC_SD )
#if !defined(PCBX7) && !defined(PCBXLITE) && !defined(PCBX9LITE)
{ "MIXSRC_SE", MIXSRC_SE },
{ "MIXSRC_SG", MIXSRC_SG },
LROT_NUMENTRY( MIXSRC_SE, MIXSRC_SE )
LROT_NUMENTRY( MIXSRC_SG, MIXSRC_SG )
#endif
#if defined(HARDWARE_SWITCH_F)
{ "MIXSRC_SF", MIXSRC_SF },
LROT_NUMENTRY( MIXSRC_SF, MIXSRC_SF )
#endif
#if defined(HARDWARE_SWITCH_H)
{ "MIXSRC_SH", MIXSRC_SH },
LROT_NUMENTRY( MIXSRC_SH, MIXSRC_SH )
#endif
{ "MIXSRC_CH1", MIXSRC_CH1 },
{ "SWSRC_LAST", SWSRC_LAST_LOGICAL_SWITCH },
{ "SWITCH_COUNT", SWSRC_COUNT },
{ "MAX_SENSORS", MAX_TELEMETRY_SENSORS },
LROT_NUMENTRY( MIXSRC_CH1, MIXSRC_CH1 )
LROT_NUMENTRY( SWSRC_LAST, SWSRC_LAST_LOGICAL_SWITCH )
LROT_NUMENTRY( SWITCH_COUNT, SWSRC_COUNT )
LROT_NUMENTRY( MAX_SENSORS, MAX_TELEMETRY_SENSORS )
{ "MAX_OUTPUT_CHANNELS", MAX_OUTPUT_CHANNELS },
{ "LIMIT_EXT_PERCENT", LIMIT_EXT_PERCENT },
{ "LIMIT_STD_PERCENT", LIMIT_STD_PERCENT },
LROT_NUMENTRY( MAX_OUTPUT_CHANNELS, MAX_OUTPUT_CHANNELS )
LROT_NUMENTRY( LIMIT_EXT_PERCENT, LIMIT_EXT_PERCENT )
LROT_NUMENTRY( 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 },
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 )
{ "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( 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 },
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 )
{"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},
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 )
{"AM_RDO", AM_RDO},
{"AM_HID", AM_HID},
{"AM_SYS", AM_SYS},
{"AM_DIR", AM_DIR},
{"AM_ARC", AM_ARC},
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)
{ 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 */
};
// 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)
-949
View File
@@ -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 <ctype.h>
#include <stdio.h>
#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<y2 ? y1 : y2, y1<y2 ? (y2-y1)+1 : (y1-y2)+1, flags);
return 0;
}
else if (y1 == y2) {
lcdDrawSolidHorizontalLine(x1<x2 ? x1 : x2, y1, x1<x2 ? (x2-x1)+1 : (x1-x2)+1, flags);
return 0;
}
}
lcdDrawLine(x1, y1, x2, y2, pat, flags);
return 0;
}
#if !defined(COLORLCD)
/*luadoc
@function lcd.getLastPos()
Returns the rightmost x position from previous output
@retval number (integer) x position
@notice Only available on Taranis
@notice For added clarity, it is recommended to use lcd.getLastRightPos()
@status current Introduced in 2.0.0
*/
/*luadoc
@function lcd.getLastRightPos()
Returns the rightest x position from previous drawtext or drawNumber output
@retval number (integer) x position
@notice Only available on Taranis
@notice This is strictly equivalent to former lcd.getLastPos()
@status current Introduced in 2.2.0
*/
static int luaLcdGetLastPos(lua_State *L)
{
lua_pushinteger(L, lcdLastRightPos);
return 1;
}
/*luadoc
@function lcd.getLastLeftPos()
Returns the leftmost x position from previous drawtext or drawNumber output
@retval number (integer) x position
@notice Only available on Taranis
@status current Introduced in 2.2.0
*/
static int luaLcdGetLeftPos(lua_State *L)
{
lua_pushinteger(L, lcdLastLeftPos);
return 1;
}
#endif // COLORLCD
/*luadoc
@function lcd.drawText(x, y, text [, flags])
Draw a text beginning at (x,y)
@param x,y (positive numbers) starting coordinate
@param text (string) text to display
@param flags (unsigned number) drawing flags. All values can be
combined together using the + character. ie BLINK + DBLSIZE.
See the [Appendix](../appendix/fonts.md) for available characters in each font set.
* `0 or not specified` normal font
* `XXLSIZE` jumbo sized font
* `DBLSIZE` double size font
* `MIDSIZE` mid sized font
* `SMLSIZE` small font
* `INVERS` inverted display
* `BLINK` blinking text
* `SHADOWED` Horus only, apply a shadow effect
@status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
*/
static int luaLcdDrawText(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
const char * s = luaL_checkstring(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0);
#if defined(COLORLCD)
if ((att&SHADOWED) && !(att&INVERS)) lcdDrawText(x+1, y+1, s, att&0xFFFF);
#endif
lcdDrawText(x, y, s, att);
return 0;
}
/*luadoc
@function lcd.drawTimer(x, y, value [, flags])
Display a value formatted as time at (x,y)
@param x,y (positive numbers) starting coordinate
@param value (number) time in seconds
@param flags (unsigned number) drawing flags:
* `0 or not specified` normal representation (minutes and seconds)
* `TIMEHOUR` display hours
* other general LCD flag also apply
* `SHADOWED` Horus only, apply a shadow effect
@status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
*/
static int luaLcdDrawTimer(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int seconds = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0);
#if defined(COLORLCD)
if (att&SHADOWED) drawTimer(x+1, y+1, seconds, (att&0xFFFF)|LEFT);
drawTimer(x, y, seconds, att|LEFT);
#else
drawTimer(x, y, seconds, att|LEFT, att);
#endif
return 0;
}
/*luadoc
@function lcd.drawNumber(x, y, value [, flags])
Display a number at (x,y)
@param x,y (positive numbers) starting coordinate
@param value (number) value to display
@param flags (unsigned number) drawing flags:
* `0 or not specified` display with no decimal (like abs())
* `PREC1` display with one decimal place (number 386 is displayed as 38.6)
* `PREC2` display with tow decimal places (number 386 is displayed as 3.86)
* other general LCD flag also apply
* `SHADOWED` Horus only, apply a shadow effect
@status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
*/
static int luaLcdDrawNumber(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int val = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0);
#if defined(COLORLCD)
if ((att&SHADOWED) && !(att&INVERS)) lcdDrawNumber(x, y, val, att&0xFFFF);
#endif
lcdDrawNumber(x, y, val, att);
return 0;
}
/*luadoc
@function lcd.drawChannel(x, y, source, flags)
Display a telemetry value at (x,y)
@param x,y (positive numbers) starting coordinate
@param source can be a source identifier (number) or a source name (string).
See getValue()
@param flags (unsigned number) drawing flags
@status current Introduced in 2.0.6, changed in 2.1.0 (only telemetry sources are valid)
*/
static int luaLcdDrawChannel(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int channel = -1;
if (lua_isnumber(L, 3)) {
channel = luaL_checkinteger(L, 3);
}
else {
const char * what = luaL_checkstring(L, 3);
LuaField field;
bool found = luaFindFieldByName(what, field);
if (found) {
channel = field.id;
}
}
unsigned int att = luaL_optunsigned(L, 4, 0);
getvalue_t value = getValue(channel);
drawSensorCustomValue(x, y, (channel-MIXSRC_FIRST_TELEM)/3, value, att);
return 0;
}
/*luadoc
@function lcd.drawSwitch(x, y, switch, flags)
Draw a text representation of switch at (x,y)
@param x,y (positive numbers) starting coordinate
@param switch (number) number of switch to display, negative number
displays negated switch
@param flags (unsigned number) drawing flags, only SMLSIZE, BLINK and INVERS.
@status current Introduced in 2.0.0
*/
static int luaLcdDrawSwitch(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int s = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0);
drawSwitch(x, y, s, att);
return 0;
}
/*luadoc
@function lcd.drawSource(x, y, source [, flags])
Displays the name of the corresponding input as defined by the source at (x,y)
@param x,y (positive numbers) starting coordinate
@param source (number) source index
@param flags (unsigned number) drawing flags
@status current Introduced in 2.0.0
*/
static int luaLcdDrawSource(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int s = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0);
drawSource(x, y, s, att);
return 0;
}
#if defined(COLORLCD)
#define LUA_BITMAPHANDLE "BITMAP*"
/*luadoc
@function Bitmap.open(name)
Loads a bitmap in memory, for later use with lcd.drawBitmap(). Bitmaps should be loaded only
once, returned object should be stored and used for drawing. If loading fails for whatever
reason the resulting bitmap object will have width and height set to zero.
Bitmap loading can fail if:
* File is not found or contains invalid image
* System is low on memory
* Combined memory usage of all Lua script bitmaps exceeds certain value
@param name (string) full path to the bitmap on SD card (i.e. “/IMAGES/test.bmp”)
@retval bitmap (object) a bitmap object that can be used with other bitmap functions
@notice Only available on Horus
@status current Introduced in 2.2.0
*/
static int luaOpenBitmap(lua_State * L)
{
const char * filename = luaL_checkstring(L, 1);
BitmapBuffer ** b = (BitmapBuffer **)lua_newuserdata(L, sizeof(BitmapBuffer *));
if (luaExtraMemoryUsage > 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<count; i++) {
lua_rawgeti(L, 4, i+1);
const char * item = luaL_checkstring(L, -1);
lcdDrawText(x+2, y+2+9*i, item, 0);
}
lcdDrawFilledRect(x+1, y+1+9*idx, w-11, 9);
lcdDrawFilledRect(x+w-10, y, 10, 11, SOLID, ERASE);
lcdDrawRect(x+w-10, y, 10, 11);
}
else if (flags & INVERS) {
lcdDrawFilledRect(x, y, w, 11);
lcdDrawFilledRect(x+w-9, y+1, 8, 9, SOLID, ERASE);
lua_rawgeti(L, 4, idx+1);
const char * item = luaL_checkstring(L, -1);
lcdDrawText(x+2, y+2, item, INVERS);
}
else {
lcdDrawFilledRect(x, y, w, 11, SOLID, ERASE);
lcdDrawRect(x, y, w, 11);
lcdDrawFilledRect(x+w-10, y+1, 9, 9, SOLID);
lua_rawgeti(L, 4, idx+1);
const char * item = luaL_checkstring(L, -1);
lcdDrawText(x+2, y+2, item, 0);
}
lcdDrawSolidHorizontalLine(x+w-8, y+3, 6);
lcdDrawSolidHorizontalLine(x+w-8, y+5, 6);
lcdDrawSolidHorizontalLine(x+w-8, y+7, 6);
return 0;
}
#endif
#if defined(COLORLCD)
/*luadoc
@function lcd.setColor(area, color)
Set a color for specific area
@param area (unsigned number) specific screen area in the list bellow
* `CUSTOM_COLOR`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_SECONDARY3`
* `COLOR_THEME_PRIMARY2`
* `COLOR_THEME_FOCUS`
* `COLOR_THEME_PRIMARY3`
* `COLOR_THEME_FOCUS`
* `COLOR_THEME_PRIMARY2`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_PRIMARY3`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_WARNING`
* `COLOR_THEME_ACTIVE`
* `COLOR_THEME_DISABLED`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_DISABLED`
* `COLOR_THEME_WARNING`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_FOCUS`
* `COLOR_THEME_PRIMARY1`
* `COLOR_THEME_PRIMARY2`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_PRIMARY2`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_FOCUS`
* `COLOR_THEME_PRIMARY2`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_PRIMARY1`
* `COLOR_THEME_SECONDARY1`
* `COLOR_THEME_SECONDARY2`
* `COLOR_THEME_SECONDARY3`
* `CUSTOM_COLOR`
@param color (number) color in 5/6/5 rgb format. The following prefined colors are available
* `WHITE`
* `GREY`
* `LIGHTGREY`
* `DARKGREY`
* `BLACK`
* `YELLOW`
* `BLUE`
* `RED`
* `DARKRED`
@notice Only available on Colorlcd radios
@status current Introduced in 2.2.0
*/
static int luaLcdSetColor(lua_State *L)
{
if (!luaLcdAllowed)
return 0;
unsigned int index = luaL_checkunsigned(L, 1) >> 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 */
};
+39 -38
View File
@@ -19,6 +19,8 @@
* GNU General Public License for more details.
*/
#define LUA_LIB
#include <ctype.h>
#include <stdio.h>
#include "opentx.h"
@@ -1737,45 +1739,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)
+33 -23
View File
@@ -19,6 +19,8 @@
* GNU General Public License for more details.
*/
#define LUA_LIB
#include <cctype>
#include <cstdio>
#include "opentx.h"
@@ -620,26 +622,34 @@ 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)
LROT_BEGIN(bitmaplib, NULL, 0)
LROT_END(bitmaplib, NULL, 0)
extern "C" {
LUALIB_API int luaopen_bitmap(lua_State * L) {
return 0;
}
}
+35 -6
View File
@@ -35,7 +35,6 @@
#include "api_filesystem.h"
#if defined(LIBOPENUI)
#include "api_colorlcd.h"
#include "libopenui.h"
#else
#include "libopenui/src/libopenui_file.h"
@@ -272,14 +271,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)
@@ -780,6 +776,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)
{
+25 -2
View File
@@ -31,7 +31,6 @@ extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <lrotable.h>
#include <lgc.h>
}
@@ -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
-1
View File
@@ -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)
-1
View File
@@ -23,7 +23,6 @@
#include "lua_widget.h"
#include "lua_api.h"
#include "api_colorlcd.h"
#define MAX_INSTRUCTIONS (20000/100)
+3 -11
View File
@@ -21,12 +21,12 @@
#include <ctype.h>
#include <stdio.h>
#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)
{
+6 -5
View File
@@ -1189,11 +1189,7 @@ void opentxClose(uint8_t shutdown)
if (shutdown) {
pulsesStop();
AUDIO_BYE();
#if defined(LUA)
luaClose(&lsScripts);
#endif
// TODO needed? telemetryEnd();
#if defined(HAPTIC)
hapticOff();
#endif
@@ -1237,6 +1233,11 @@ void opentxClose(uint8_t shutdown)
lsWidgets = 0;
#endif
#endif
#if defined(LUA)
// the script context needs to be closed *after*
// the widgets, as it has been the first to be opened
luaClose(&lsScripts);
#endif
#if defined(SDCARD)
sdDone();
+2
View File
@@ -66,6 +66,8 @@ add_definitions(
-DSDRAM -DCOLORLCD -DLIBOPENUI
-DHARDWARE_TOUCH -DHARDWARE_KEYS)
set(SDRAM ON)
add_definitions(-DEEPROM_VARIANT=0 -DAUDIO -DVOICE -DRTCLOCK)
add_definitions(-DGPS_USART_BAUDRATE=${INTERNAL_GPS_BAUDRATE})
add_definitions(-DPWR_BUTTON_${PWR_BUTTON})
+31 -45
View File
@@ -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"
@@ -261,7 +260,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)));
}
@@ -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;
}
}
@@ -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 */
@@ -444,17 +444,15 @@ 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, 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 +556,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;
@@ -576,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 */
@@ -591,19 +590,6 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
lua_unlock(L);
}
LUA_API void lua_pushrotable (lua_State *L, void *p) {
lua_lock(L);
setrvalue(L->top, p);
api_incr_top(L);
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);
@@ -613,30 +599,27 @@ LUA_API int lua_pushthread (lua_State *L) {
return (G(L)->mainthread == L);
}
LUA_API void lua_pushrotable (lua_State *L, const ROTable *t) {
lua_lock(L);
sethvalue(L, L->top, cast(Table *, t));
api_incr_top(L);
lua_unlock(L);
}
/*
** get functions (Lua -> stack)
*/
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 {
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);
}
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);
}
@@ -797,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);
@@ -811,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--;
@@ -825,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);
@@ -846,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);
@@ -855,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) {
+36 -8
View File
@@ -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 */
}
}
+6
View File
@@ -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);
+46 -38
View File
@@ -4,19 +4,22 @@
** See Copyright Notice in lua.h
*/
#define lbaselib_c
#define LUA_LIB
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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},
#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}
};
extern LROT_TABLE(etxlib);
#if 0
// TODO
const luaR_value_entry baselib_vals[] = {
{"_VERSION", LUA_VERSION},
{NULL, 0}
};
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)
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 */
}
+18 -20
View File
@@ -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;
}
+1 -4
View File
@@ -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;
+95 -51
View File
@@ -14,72 +14,116 @@
#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"
#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);
/*
** 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},
extern LROT_TABLE(tablib);
#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}
/* _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( bit32, bitlib )
LROT_TABENTRY( lcd, lcdlib )
LROT_TABENTRY( model, modellib )
LROT_TABENTRY( bitmap, bitmaplib )
LROT_TABENTRY( Bitmap, bitmaplib ) /* TODO: obsolete after 2.9 */
#if defined(COLORLCD)
LROT_TABENTRY( table, tablib )
#endif
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 */
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);
}
/* 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);
}
lua_pop(L, 1); /* remove _PRELOAD table */
}
+15 -76
View File
@@ -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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#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}
};
LROT_BEGIN(file_handle, NULL, LROT_MASK_GC)
LROT_FUNCENTRY( __gc, f_gc )
LROT_END(file_handle, NULL, LROT_MASK_GC)
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 */
}
#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
+11
View File
@@ -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
+37 -42
View File
@@ -4,19 +4,17 @@
** See Copyright Notice in lua.h
*/
#define lmathlib_c
#define LUA_LIB
#include <stdlib.h>
#include <math.h>
#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},
#if defined(LUA_COMPAT_LOG10)
{"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_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)
LROT_FUNCENTRY( log10, math_log10)
#endif
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
+43 -19
View File
@@ -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,12 +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 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))
#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))
@@ -155,7 +158,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,8 +165,10 @@ 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 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 */
@@ -192,18 +196,12 @@ 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) \
{ 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 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); }
@@ -238,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)
@@ -547,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
*/
@@ -567,17 +579,29 @@ typedef struct Node {
typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of `node' array */
struct Table *metatable;
/* flags & 1<<p means tagmethod(p) is not present */
/* lsizenode = log2 of size of `node' array */
CommonTable;
int sizearray; /* size of `array' array */
TValue *array; /* array part */
Node *node;
Node *lastfree; /* any free position is before this position */
GCObject *gclist;
int sizearray; /* size of `array' array */
} Table;
typedef struct ROTable_entry {
const char *key;
const TValue value;
} ROTable_entry;
typedef struct ROTable {
/* next always has the value (GCObject *)((size_t) 1); */
/* flags & 1<<p means tagmethod(p) is not present */
/* lsizenode is the number of ROTable entries */
/* Like TStrings, the ROTable_entry vector follows the ROTable */
CommonTable;
const ROTable_entry *entry;
} ROTable;
/*
+52
View File
@@ -0,0 +1,52 @@
#ifndef lro_defs_h
#define lro_defs_h
#include "lua.h"
#include "lobject.h"
#include "llimits.h"
#include "ltm.h"
/* Macros used to declare rotable entries */
#define LRO_STRKEY(k) k
#define LRO_FUNCVAL(v) {{.f = v}, LUA_TLCF}
#define LRO_LUDATA(v) {{.p = (void *) v}, LUA_TLIGHTUSERDATA}
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
#define LRO_ROVAL(v) {{.gc = cast(GCObject *, &(v ## _ROTable))}, LUA_TTBLROF}
#define LROT_MARKED 0 //<<<<<<<<<< *** TBD *** >>>>>>>>>>>
#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 const 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(const ROTable_entry *, rt ## _entries) };
#define LROT_BREAK(rt) };
#define LROT_MASK(m) cast(lu_byte, 1<<TM_ ## m)
/*
* These are statically coded can be any combination of the fast index tags
* listed in ltm.h: EQ, GC, INDEX, LEN, MODE, NEWINDEX or combined by anding
* GC+INDEX is the only common combination used, hence the combinaton macro
*/
#define LROT_MASK_EQ LROT_MASK(EQ)
#define LROT_MASK_GC LROT_MASK(GC)
#define LROT_MASK_INDEX LROT_MASK(INDEX)
#define LROT_MASK_LEN LROT_MASK(LEN)
#define LROT_MASK_MODE LROT_MASK(MODE)
#define LROT_MASK_NEWINDEX LROT_MASK(NEWINDEX)
#define LROT_MASK_GC_INDEX (LROT_MASK_GC | LROT_MASK_INDEX)
#endif
-106
View File
@@ -1,106 +0,0 @@
/* Read-only tables for Lua */
#include <string.h>
#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)) {
setlfvalue(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;
}
-46
View File
@@ -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
+21
View File
@@ -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 */
+13 -2
View File
@@ -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
+24 -36
View File
@@ -4,6 +4,8 @@
** See Copyright Notice in lua.h
*/
#define lstrlib_c
#define LUA_LIB
#include <ctype.h>
#include <stddef.h>
@@ -11,8 +13,6 @@
#include <string.h>
#include <stdio.h>
#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
+158 -13
View File
@@ -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));
}
@@ -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));
@@ -209,10 +215,7 @@ static int computesizes (int nums[], int *narray) {
}
if (a == *narray) break; /* all elements already counted */
}
if (n - *narray > 1024)
*narray += 1024;
else
*narray = n;
*narray = n;
lua_assert(*narray/2 <= na && na <= *narray);
return na;
}
@@ -306,7 +309,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);
@@ -406,6 +408,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");
@@ -446,6 +449,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];
@@ -465,8 +470,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))
@@ -493,7 +504,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 */
@@ -510,7 +523,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);
@@ -518,7 +534,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);
@@ -577,6 +596,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 <key><TValue value> 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)
@@ -585,6 +732,4 @@ Node *luaH_mainposition (const Table *t, const TValue *key) {
return mainposition(t, key);
}
int luaH_isdummy (Node *n) { return isdummy(n); }
#endif
+5
View File
@@ -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);
+12 -19
View File
@@ -4,11 +4,11 @@
** See Copyright Notice in lua.h
*/
#define ltablib_c
#define LUA_LIB
#include <stddef.h>
#define ltablib_c
#include "lua.h"
#include "lauxlib.h"
@@ -256,27 +256,20 @@ static int sort (lua_State *L) {
/* }====================================================== */
const luaL_Reg tab_funcs[] = {
{"concat", tconcat},
LROT_BEGIN(tablib, NULL, 0)
LROT_FUNCENTRY( concat, tconcat)
#if defined(LUA_COMPAT_MAXN)
{"maxn", maxn},
LROT_FUNCENTRY( maxn, maxn)
#endif
{"insert", tinsert},
{"pack", pack},
{"unpack", unpack},
{"remove", tremove},
{"sort", sort},
{NULL, NULL}
};
LROT_FUNCENTRY( insert, tinsert)
LROT_FUNCENTRY( pack, pack)
LROT_FUNCENTRY( unpack, unpack)
LROT_FUNCENTRY( remove, tremove)
LROT_FUNCENTRY( sort, sort)
LROT_END(tablib, NULL, 0)
LUAMOD_API int luaopen_table (lua_State *L) {
luaL_newlib(L, tab_funcs);
#if defined(LUA_COMPAT_UNPACK)
/* _G.unpack = table.unpack */
lua_getfield(L, -1, "unpack");
lua_setglobal(L, "unpack");
#endif
return 1;
return 0;
}
+3 -1
View File
@@ -23,7 +23,9 @@ static const char udatatypename[] = "userdata";
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
"no value",
"nil", "boolean", "rotable", "lightfunction", udatatypename, "number",
"nil", "boolean",
"_obsolete_", "_obsolete_", /* removed LUA_TROTABLE and LUA_TLIGHTFUNCTION */
udatatypename, "number",
"string", "table", "function", udatatypename, "thread",
"proto", "upval" /* these last two cases are used for tests only */
};
+9 -4
View File
@@ -77,8 +77,6 @@ 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
@@ -216,8 +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_pushlightfunction) (lua_State *L, void *p);
LUA_API void (lua_pushrotable) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
@@ -431,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.
+2 -3
View File
@@ -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
/*
** ==================================================================
@@ -560,6 +561,4 @@
** without modifying the main part of the file.
*/
#define LUA_MAX_ROTABLE_NAME 32
#endif
+5 -5
View File
@@ -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; i<n; i++) f->locvars[i].varname=NULL;
for (i=0; i<n; i++)
{
f->locvars[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; i<n; i++) f->upvalues[i].name=Load_String(S);
for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
}
static void LoadFunction(LoadState* S, Proto* f)
+20 -53
View File
@@ -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,10 +121,9 @@ 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) || ttislightfunction(tm)) {
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 = ll<lr ? ll : lr;
int s = memcmp(l, r, lm);
return s ? s : (lr == lm ? (ll == lm ? 0 : 1) : -1);
}
}
@@ -283,11 +262,8 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
case LUA_TNIL: return 1;
case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(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_TLIGHTUSERDATA: return pvalue(t1) == pvalue(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: {
@@ -296,7 +272,8 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
tm = get_equalTM(L, uvalue(t1)->metatable, 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);
@@ -620,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;