chores: update to LUA 5.3 (#4203)
Co-authored-by: Peter Feerick <peter.feerick@gmail.com> Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
co-authored by
Peter Feerick
philmoz
parent
28b0cb9e71
commit
47cba2211f
@@ -81,6 +81,8 @@ set(LUA_SRC
|
||||
lstrlib.c
|
||||
)
|
||||
|
||||
add_compile_definitions(LUA_COMPAT_5_2)
|
||||
|
||||
foreach(FILE ${LUA_SRC})
|
||||
set(SRC ${SRC} ${LUA_DIR}/${FILE})
|
||||
endforeach()
|
||||
|
||||
+108
-104
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "libopenui.h"
|
||||
@@ -67,7 +68,7 @@ Clear the LCD screen
|
||||
static int luaLcdClear(lua_State * L)
|
||||
{
|
||||
if (luaLcdAllowed && luaLcdBuffer) {
|
||||
LcdFlags flags = luaL_optunsigned(L, 1, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX));
|
||||
LcdFlags flags = luaL_optinteger(L, 1, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX));
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->clear(flags);
|
||||
}
|
||||
@@ -114,7 +115,7 @@ static int luaLcdDrawPoint(lua_State *L)
|
||||
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
LcdFlags flags = luaL_optunsigned(L, 3, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 3, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
// drawPixel uses color value directly; hence COLOR_VAL again
|
||||
@@ -146,12 +147,12 @@ static int luaLcdDrawLine(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
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_optunsigned(L, 6, 0);
|
||||
coord_t x1 = luaL_checkinteger(L, 1);
|
||||
coord_t y1 = luaL_checkinteger(L, 2);
|
||||
coord_t x2 = luaL_checkinteger(L, 3);
|
||||
coord_t y2 = luaL_checkinteger(L, 4);
|
||||
uint8_t pat = luaL_checkinteger(L, 5);
|
||||
LcdFlags flags = luaL_optinteger(L, 6, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (x1 > LCD_W || y1 > LCD_H || x2 > LCD_W || y2 > LCD_H)
|
||||
@@ -192,7 +193,7 @@ static void drawString(lua_State *L, const char * s, LcdFlags flags)
|
||||
if (invers) {
|
||||
// Find inverse color or read from optional Lua argument
|
||||
LcdFlags color = colorToRGB(flags);
|
||||
LcdFlags invColor = luaL_optunsigned(L, 5, ~0u); // ~0 is impossible for color flag!
|
||||
LcdFlags invColor = luaL_optinteger(L, 5, ~0u); // ~0 is impossible for color flag!
|
||||
if (invColor == ~0u) {
|
||||
RGB_SPLIT(COLOR_VAL(color), r, g, b);
|
||||
invColor = COLOR2FLAGS(RGB_JOIN(31 - r, 63 - g, 31 - b));
|
||||
@@ -240,7 +241,7 @@ Draw a text beginning at (x,y)
|
||||
static int luaLcdDrawText(lua_State *L)
|
||||
{
|
||||
const char * s = luaL_checkstring(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
drawString(L, s, flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -261,7 +262,7 @@ Get the width and height of a text string drawn with flags
|
||||
static int luaLcdSizeText(lua_State *L)
|
||||
{
|
||||
const char * s = luaL_checkstring(L, 1);
|
||||
LcdFlags flags = luaL_optunsigned(L, 2, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 2, 0);
|
||||
lua_pushinteger(L, getTextWidth(s, 0, flags));
|
||||
lua_pushinteger(L, getFontHeight(flags & 0xFFFF));
|
||||
return 2;
|
||||
@@ -295,7 +296,7 @@ static int luaLcdDrawTextLines(lua_State *L)
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
point_t maxP = {0,0};
|
||||
const char * s = luaL_checkstring(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 6, 0);
|
||||
|
||||
bool invers = flags & INVERS;
|
||||
if (flags & BLINK)
|
||||
@@ -304,7 +305,7 @@ static int luaLcdDrawTextLines(lua_State *L)
|
||||
if (invers) {
|
||||
// Find inverse color or read from optional Lua argument
|
||||
LcdFlags color = colorToRGB(flags);
|
||||
LcdFlags invColor = luaL_optunsigned(L, 7, ~0u); // ~0 is impossible for color flag!
|
||||
LcdFlags invColor = luaL_optinteger(L, 7, ~0u); // ~0 is impossible for color flag!
|
||||
if (invColor == ~0u) {
|
||||
RGB_SPLIT(COLOR_VAL(color), r, g, b);
|
||||
invColor = COLOR2FLAGS(RGB_JOIN(31 - r, 63 - g, 31 - b));
|
||||
@@ -351,7 +352,7 @@ static int luaLcdDrawTimer(lua_State *L)
|
||||
{
|
||||
char s[LEN_TIMER_STRING];
|
||||
int tme = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
TimerOptions timerOptions;
|
||||
timerOptions.options = (flags & TIMEHOUR) != 0 ? SHOW_TIME : SHOW_TIMER;
|
||||
getTimerString(s, tme, timerOptions);
|
||||
@@ -378,7 +379,7 @@ static int luaLcdDrawNumber(lua_State *L)
|
||||
{
|
||||
char s[49];
|
||||
int val = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
formatNumberAsString(s, 49, val, flags & 0xFFFF);
|
||||
drawString(L, s, flags);
|
||||
return 0;
|
||||
@@ -417,7 +418,7 @@ static int luaLcdDrawChannel(lua_State *L)
|
||||
channel = field.id;
|
||||
}
|
||||
}
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
getvalue_t value = getValue(channel);
|
||||
luaLcdBuffer->drawSensorCustomValue(x, y, (channel-MIXSRC_FIRST_TELEM)/3, value, flags);
|
||||
@@ -447,7 +448,7 @@ static int luaLcdDrawSwitch(lua_State *L)
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int s = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawSwitch(x, y, s, flags);
|
||||
|
||||
@@ -475,7 +476,7 @@ static int luaLcdDrawSource(lua_State *L)
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int s = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawSource(x, y, s, flags);
|
||||
|
||||
@@ -587,15 +588,15 @@ Return a resized bitmap object
|
||||
static int luaBitmapResize(lua_State * L)
|
||||
{
|
||||
const BitmapBuffer * b = checkBitmap(L, 1);
|
||||
unsigned int w = luaL_checkunsigned(L, 2);
|
||||
unsigned int h = luaL_checkunsigned(L, 3);
|
||||
coord_t w = luaL_checkinteger(L, 2);
|
||||
coord_t h = luaL_checkinteger(L, 3);
|
||||
|
||||
if (!b) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BitmapBuffer **n = (BitmapBuffer**)lua_newuserdata(L, sizeof(BitmapBuffer*));
|
||||
BitmapBuffer **n = (BitmapBuffer**)lua_newuserdata(L, sizeof(void*));
|
||||
|
||||
if (luaExtraMemoryUsage > LUA_MEM_EXTRA_MAX) {
|
||||
// already allocated more than max allowed, fail
|
||||
@@ -689,9 +690,9 @@ static int luaLcdDrawBitmap(lua_State *L)
|
||||
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);
|
||||
coord_t x = luaL_checkinteger(L, 2);
|
||||
coord_t y = luaL_checkinteger(L, 3);
|
||||
coord_t scale = luaL_optinteger(L, 4, 0);
|
||||
if (scale) {
|
||||
luaLcdBuffer->drawBitmap(x, y, b, 0, 0, 0, 0, scale/100.0f);
|
||||
}
|
||||
@@ -727,9 +728,9 @@ static int luaLcdDrawBitmapPattern(lua_State *L)
|
||||
const char* m = luaL_checkstring(L, 1);
|
||||
|
||||
if (m) {
|
||||
auto x = luaL_checkunsigned(L, 2);
|
||||
auto y = luaL_checkunsigned(L, 3);
|
||||
auto flags = luaL_optunsigned(L, 4, 0);
|
||||
auto x = luaL_checkinteger(L, 2);
|
||||
auto y = luaL_checkinteger(L, 3);
|
||||
auto flags = (LcdFlags)luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawBitmapPattern(x, y, reinterpret_cast<const MaskBitmap*>(m), flags);
|
||||
}
|
||||
@@ -764,11 +765,11 @@ static int luaLcdDrawBitmapPatternPie(lua_State *L)
|
||||
const char* m = luaL_checkstring(L, 1);
|
||||
|
||||
if (m) {
|
||||
auto x = luaL_checkunsigned(L, 2);
|
||||
auto y = luaL_checkunsigned(L, 3);
|
||||
auto startAngle = luaL_checkinteger(L, 4);
|
||||
auto endAngle = luaL_checkinteger(L, 5);
|
||||
auto flags = luaL_optunsigned(L, 6, 0);
|
||||
coord_t x = luaL_checkinteger(L, 2);
|
||||
coord_t y = luaL_checkinteger(L, 3);
|
||||
int startAngle = luaL_checkinteger(L, 4);
|
||||
int endAngle = luaL_checkinteger(L, 5);
|
||||
LcdFlags flags = luaL_optinteger(L, 6, 0);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawBitmapPatternPie(x, y, reinterpret_cast<const MaskBitmap*>(m), flags, startAngle, endAngle);
|
||||
}
|
||||
@@ -804,12 +805,12 @@ static int luaLcdDrawRectangle(lua_State *L)
|
||||
int w = luaL_checkinteger(L, 3);
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 5, 0);
|
||||
flags = colorToRGB(flags);
|
||||
unsigned int t = luaL_optunsigned(L, 6, 1);
|
||||
uint8_t opacity = luaL_optunsigned(L, 7, 0) & 0x0F;
|
||||
uint8_t thickness = luaL_optinteger(L, 6, 1);
|
||||
uint8_t opacity = luaL_optinteger(L, 7, 0) & 0x0F;
|
||||
|
||||
luaLcdBuffer->drawRect(x, y, w, h, t, SOLID, flags, opacity);
|
||||
luaLcdBuffer->drawRect(x, y, w, h, thickness, SOLID, flags, opacity);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -841,9 +842,9 @@ static int luaLcdDrawFilledRectangle(lua_State *L)
|
||||
int w = luaL_checkinteger(L, 3);
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 5, 0);
|
||||
flags = colorToRGB(flags);
|
||||
uint8_t opacity = luaL_optunsigned(L, 6, 0) & 0x0F;
|
||||
uint8_t opacity = luaL_optinteger(L, 6, 0) & 0x0F;
|
||||
|
||||
luaLcdBuffer->drawFilledRect(x, y, w, h, SOLID, flags, opacity);
|
||||
|
||||
@@ -876,7 +877,7 @@ static int luaLcdInvertRect(lua_State *L)
|
||||
int w = luaL_checkinteger(L, 3);
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 5, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->invertRect(x, y, w, h, flags);
|
||||
@@ -914,7 +915,7 @@ static int luaLcdDrawGauge(lua_State *L)
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
int num = luaL_checkinteger(L, 5);
|
||||
int den = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
LcdFlags flags = luaL_optinteger(L, 7, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawRect(x, y, w, h, 1, 0xff, flags);
|
||||
@@ -937,8 +938,8 @@ Please notice that changing theme colors affects not only other Lua widgets, but
|
||||
*/
|
||||
static int luaLcdSetColor(lua_State *L)
|
||||
{
|
||||
unsigned int index = COLOR_VAL(luaL_checkunsigned(L, 1));
|
||||
uint16_t color = COLOR_VAL(colorToRGB(luaL_checkunsigned(L, 2)));
|
||||
unsigned int index = COLOR_VAL((uint32_t)luaL_checkinteger(L, 1));
|
||||
uint16_t color = COLOR_VAL(colorToRGB(luaL_checkinteger(L, 2)));
|
||||
|
||||
if (index < LCD_COLOR_COUNT && lcdColorTable[index] != color) {
|
||||
lcdColorTable[index] = color;
|
||||
@@ -963,11 +964,13 @@ Get the color value from flags
|
||||
|
||||
static int luaLcdGetColor(lua_State *L)
|
||||
{
|
||||
LcdFlags flags = luaL_checkunsigned(L, 1);
|
||||
if ((flags & RGB_FLAG) || (COLOR_VAL(flags) & 0xFF) < LCD_COLOR_COUNT)
|
||||
lua_pushunsigned(L, colorToRGB(flags) & (COLOR_MASK(~0u) | RGB_FLAG));
|
||||
else
|
||||
LcdFlags flags = luaL_checkinteger(L, 1);
|
||||
if ((flags & RGB_FLAG) || (COLOR_VAL(flags) & 0xFF) < LCD_COLOR_COUNT) {
|
||||
LcdFlags col = colorToRGB(flags) & (COLOR_MASK(~0u) | RGB_FLAG);
|
||||
lua_pushinteger(L, col);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -994,7 +997,7 @@ static int luaRGB(lua_State *L)
|
||||
{
|
||||
int r, g, b;
|
||||
if (lua_gettop(L) == 1) {
|
||||
int color = luaL_checkinteger(L, 1);
|
||||
uint32_t color = luaL_checkinteger(L, 1);
|
||||
r = (color >> 16) & 0xFF;
|
||||
g = (color >> 8) & 0xFF;
|
||||
b = color & 0xFF;
|
||||
@@ -1003,7 +1006,8 @@ static int luaRGB(lua_State *L)
|
||||
g = luaL_checkinteger(L, 2);
|
||||
b = luaL_checkinteger(L, 3);
|
||||
}
|
||||
lua_pushinteger(L, COLOR2FLAGS(RGB(r, g, b)) | RGB_FLAG);
|
||||
LcdFlags res = COLOR2FLAGS(RGB(r, g, b)) | RGB_FLAG;
|
||||
lua_pushinteger(L, res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1025,10 +1029,10 @@ static int luaLcdDrawCircle(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
return 0;
|
||||
|
||||
coord_t x = luaL_checkunsigned(L, 1);
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
coord_t x = luaL_checkinteger(L, 1);
|
||||
coord_t y = luaL_checkinteger(L, 2);
|
||||
coord_t r = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawCircle(x, y, r, flags);
|
||||
@@ -1054,10 +1058,10 @@ static int luaLcdDrawFilledCircle(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
return 0;
|
||||
|
||||
coord_t x = luaL_checkunsigned(L, 1);
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
coord_t x = luaL_checkinteger(L, 1);
|
||||
coord_t y = luaL_checkinteger(L, 2);
|
||||
coord_t r = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optinteger(L, 4, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawFilledCircle(x, y, r, flags);
|
||||
@@ -1081,13 +1085,13 @@ static int luaLcdDrawTriangle(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
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);
|
||||
coord_t x3 = luaL_checkunsigned(L, 5);
|
||||
coord_t y3 = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
coord_t x1 = luaL_checkinteger(L, 1);
|
||||
coord_t y1 = luaL_checkinteger(L, 2);
|
||||
coord_t x2 = luaL_checkinteger(L, 3);
|
||||
coord_t y2 = luaL_checkinteger(L, 4);
|
||||
coord_t x3 = luaL_checkinteger(L, 5);
|
||||
coord_t y3 = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optinteger(L, 7, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawLine(x1, y1, x2, y2, SOLID, flags);
|
||||
@@ -1113,13 +1117,13 @@ static int luaLcdDrawFilledTriangle(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
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);
|
||||
coord_t x3 = luaL_checkunsigned(L, 5);
|
||||
coord_t y3 = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
coord_t x1 = luaL_checkinteger(L, 1);
|
||||
coord_t y1 = luaL_checkinteger(L, 2);
|
||||
coord_t x2 = luaL_checkinteger(L, 3);
|
||||
coord_t y2 = luaL_checkinteger(L, 4);
|
||||
coord_t x3 = luaL_checkinteger(L, 5);
|
||||
coord_t y3 = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optinteger(L, 7, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawFilledTriangle(x1, y1, x2, y2, x3, y3, flags);
|
||||
@@ -1147,12 +1151,12 @@ static int luaLcdDrawArc(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
return 0;
|
||||
|
||||
coord_t x = luaL_checkunsigned(L, 1);
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
int start = luaL_checkunsigned(L, 4);
|
||||
int end = luaL_checkunsigned(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
coord_t x = luaL_checkinteger(L, 1);
|
||||
coord_t y = luaL_checkinteger(L, 2);
|
||||
coord_t r = luaL_checkinteger(L, 3);
|
||||
int start = luaL_checkinteger(L, 4);
|
||||
int end = luaL_checkinteger(L, 5);
|
||||
LcdFlags flags = luaL_optinteger(L, 6, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (r > 0)
|
||||
@@ -1181,12 +1185,12 @@ static int luaLcdDrawPie(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
return 0;
|
||||
|
||||
coord_t x = luaL_checkunsigned(L, 1);
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
int start = luaL_checkunsigned(L, 4);
|
||||
int end = luaL_checkunsigned(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
coord_t x = luaL_checkinteger(L, 1);
|
||||
coord_t y = luaL_checkinteger(L, 2);
|
||||
coord_t r = luaL_checkinteger(L, 3);
|
||||
int start = luaL_checkinteger(L, 4);
|
||||
int end = luaL_checkinteger(L, 5);
|
||||
LcdFlags flags = luaL_optinteger(L, 6, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (r > 0)
|
||||
@@ -1215,13 +1219,13 @@ static int luaLcdDrawAnnulus(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
return 0;
|
||||
|
||||
coord_t x = luaL_checkunsigned(L, 1);
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r1 = luaL_checkunsigned(L, 3);
|
||||
coord_t r2 = luaL_checkunsigned(L, 4);
|
||||
int start = luaL_checkunsigned(L, 5);
|
||||
int end = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
coord_t x = luaL_checkinteger(L, 1);
|
||||
coord_t y = luaL_checkinteger(L, 2);
|
||||
coord_t r1 = luaL_checkinteger(L, 3);
|
||||
coord_t r2 = luaL_checkinteger(L, 4);
|
||||
int start = luaL_checkinteger(L, 5);
|
||||
int end = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optinteger(L, 7, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawAnnulusSector(x, y, r1, r2, start, end, flags);
|
||||
@@ -1249,16 +1253,16 @@ static int luaLcdDrawLineWithClipping(lua_State *L)
|
||||
if (!luaLcdAllowed || !luaLcdBuffer)
|
||||
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);
|
||||
coord_t xmin = luaL_checkunsigned(L, 5);
|
||||
coord_t xmax = luaL_checkunsigned(L, 6);
|
||||
coord_t ymin = luaL_checkunsigned(L, 7);
|
||||
coord_t ymax = luaL_checkunsigned(L, 8);
|
||||
uint8_t pat = luaL_checkunsigned(L, 9);
|
||||
LcdFlags flags = luaL_optunsigned(L, 10, 0);
|
||||
coord_t x1 = luaL_checkinteger(L, 1);
|
||||
coord_t y1 = luaL_checkinteger(L, 2);
|
||||
coord_t x2 = luaL_checkinteger(L, 3);
|
||||
coord_t y2 = luaL_checkinteger(L, 4);
|
||||
coord_t xmin = luaL_checkinteger(L, 5);
|
||||
coord_t xmax = luaL_checkinteger(L, 6);
|
||||
coord_t ymin = luaL_checkinteger(L, 7);
|
||||
coord_t ymax = luaL_checkinteger(L, 8);
|
||||
uint8_t pat = luaL_checkinteger(L, 9);
|
||||
LcdFlags flags = luaL_optinteger(L, 10, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
// backup clipping rect
|
||||
@@ -1359,11 +1363,11 @@ static int luaLcdDrawHudRectangle(lua_State *L)
|
||||
|
||||
float pitch = luaL_checknumber(L, 1);
|
||||
float roll = luaL_checknumber(L, 2);
|
||||
coord_t xmin = luaL_checkunsigned(L, 3);
|
||||
coord_t xmax = luaL_checkunsigned(L, 4);
|
||||
coord_t ymin = luaL_checkunsigned(L, 5);
|
||||
coord_t ymax = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
coord_t xmin = luaL_checkinteger(L, 3);
|
||||
coord_t xmax = luaL_checkinteger(L, 4);
|
||||
coord_t ymin = luaL_checkinteger(L, 5);
|
||||
coord_t ymax = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optinteger(L, 7, 0);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
drawHudRectangle(luaLcdBuffer, pitch, roll, xmin, xmax, ymin, ymax, flags);
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "definitions.h"
|
||||
#include "lua_states.h"
|
||||
|
||||
EXTERN_C(LUALIB_API int luaopen_bitmap(lua_State * L));
|
||||
EXTERN_C(LUALIB_API int luaopen_lvgl(lua_State * L));
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
|
||||
#define LUA_LIB
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "lua_api.h"
|
||||
#include "api_filesystem.h"
|
||||
|
||||
@@ -83,6 +82,9 @@ int luaDir(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void luaPushDateTime(lua_State * L, uint32_t year, uint32_t mon, uint32_t day,
|
||||
uint32_t hour, uint32_t min, uint32_t sec);
|
||||
|
||||
/*luadoc
|
||||
@function fstat(path)
|
||||
|
||||
@@ -178,7 +180,7 @@ int luaDelete(lua_State* L)
|
||||
TRACE("luaDelete cannot delete file/folder %s", filename);
|
||||
}
|
||||
|
||||
lua_pushunsigned(L, res);
|
||||
lua_pushinteger(L, res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "definitions.h"
|
||||
#include "lua_states.h"
|
||||
|
||||
#define DIR_METATABLE "DIR*"
|
||||
|
||||
|
||||
@@ -178,9 +178,9 @@ static int luaGetVersion(lua_State * L)
|
||||
{
|
||||
lua_pushstring(L, VERSION);
|
||||
lua_pushstring(L, RADIO_VERSION);
|
||||
lua_pushnumber(L, VERSION_MAJOR);
|
||||
lua_pushnumber(L, VERSION_MINOR);
|
||||
lua_pushnumber(L, VERSION_REVISION);
|
||||
lua_pushinteger(L, VERSION_MAJOR);
|
||||
lua_pushinteger(L, VERSION_MINOR);
|
||||
lua_pushinteger(L, VERSION_REVISION);
|
||||
lua_pushstring(L, VERSION_OSNAME);
|
||||
return 6;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ overflows will not happen.
|
||||
*/
|
||||
static int luaGetTime(lua_State * L)
|
||||
{
|
||||
lua_pushunsigned(L, get_tmr10ms());
|
||||
lua_pushinteger(L, get_tmr10ms());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ in 2038.
|
||||
#if defined(RTCLOCK)
|
||||
static int luaGetRtcTime(lua_State * L)
|
||||
{
|
||||
lua_pushunsigned(L, g_rtcTime);
|
||||
lua_pushinteger(L, g_rtcTime);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -300,7 +300,7 @@ static void luaPushCells(lua_State* L, TelemetrySensor & telemetrySensor, Teleme
|
||||
else {
|
||||
lua_createtable(L, telemetryItem.cells.count, 0);
|
||||
for (int i = 0; i < telemetryItem.cells.count; i++) {
|
||||
lua_pushnumber(L, i + 1);
|
||||
lua_pushinteger(L, i + 1);
|
||||
lua_pushnumber(L, telemetryItem.cells.values[i].value * 0.01f);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
@@ -874,7 +874,7 @@ Return rotary encoder current speed
|
||||
*/
|
||||
static int luaGetRotEncSpeed(lua_State * L)
|
||||
{
|
||||
lua_pushunsigned(L, max(rotaryEncoderGetAccel(), (int8_t)1));
|
||||
lua_pushinteger(L, max(rotaryEncoderGetAccel(), (int8_t)1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -891,9 +891,9 @@ Return rotary encoder mode
|
||||
static int luaGetRotEncMode(lua_State * L)
|
||||
{
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(USE_HATS_AS_KEYS)
|
||||
lua_pushunsigned(L, g_eeGeneral.rotEncMode);
|
||||
lua_pushinteger(L, g_eeGeneral.rotEncMode);
|
||||
#else
|
||||
lua_pushunsigned(L, 0);
|
||||
lua_pushinteger(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
@@ -929,10 +929,10 @@ static int luaSportTelemetryPop(lua_State * L)
|
||||
for (uint8_t i=0; i<sizeof(packet); i++) {
|
||||
luaInputTelemetryFifo->pop(packet.raw[i]);
|
||||
}
|
||||
lua_pushnumber(L, packet.physicalId);
|
||||
lua_pushnumber(L, packet.primId);
|
||||
lua_pushnumber(L, packet.dataId);
|
||||
lua_pushunsigned(L, packet.value);
|
||||
lua_pushinteger(L, packet.physicalId);
|
||||
lua_pushinteger(L, packet.primId);
|
||||
lua_pushinteger(L, packet.dataId);
|
||||
lua_pushinteger(L, packet.value);
|
||||
return 4;
|
||||
}
|
||||
|
||||
@@ -999,7 +999,7 @@ static int luaSportTelemetryPush(lua_State * L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint16_t dataId = luaL_checkunsigned(L, 3);
|
||||
uint16_t dataId = luaL_checkinteger(L, 3);
|
||||
|
||||
if (outputTelemetryBuffer.isAvailable()) {
|
||||
for (uint8_t i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
@@ -1007,17 +1007,17 @@ static int luaSportTelemetryPush(lua_State * L)
|
||||
if (sensor.id == dataId) {
|
||||
if (sensor.frskyInstance.rxIndex == TELEMETRY_ENDPOINT_SPORT) {
|
||||
SportTelemetryPacket packet;
|
||||
packet.physicalId = getDataId(luaL_checkunsigned(L, 1));
|
||||
packet.primId = luaL_checkunsigned(L, 2);
|
||||
packet.physicalId = getDataId(luaL_checkinteger(L, 1));
|
||||
packet.primId = luaL_checkinteger(L, 2);
|
||||
packet.dataId = dataId;
|
||||
packet.value = luaL_checkunsigned(L, 4);
|
||||
packet.value = luaL_checkinteger(L, 4);
|
||||
outputTelemetryBuffer.pushSportPacketWithBytestuffing(packet);
|
||||
}
|
||||
else {
|
||||
outputTelemetryBuffer.sport.physicalId = getDataId(luaL_checkunsigned(L, 1));
|
||||
outputTelemetryBuffer.sport.primId = luaL_checkunsigned(L, 2);
|
||||
outputTelemetryBuffer.sport.physicalId = getDataId(luaL_checkinteger(L, 1));
|
||||
outputTelemetryBuffer.sport.primId = luaL_checkinteger(L, 2);
|
||||
outputTelemetryBuffer.sport.dataId = dataId;
|
||||
outputTelemetryBuffer.sport.value = luaL_checkunsigned(L, 4);
|
||||
outputTelemetryBuffer.sport.value = luaL_checkinteger(L, 4);
|
||||
}
|
||||
outputTelemetryBuffer.setDestination(sensor.frskyInstance.rxIndex);
|
||||
lua_pushboolean(L, true);
|
||||
@@ -1028,10 +1028,10 @@ static int luaSportTelemetryPush(lua_State * L)
|
||||
// sensor not found, we send the frame to the SPORT line
|
||||
{
|
||||
SportTelemetryPacket packet;
|
||||
packet.physicalId = getDataId(luaL_checkunsigned(L, 1));
|
||||
packet.primId = luaL_checkunsigned(L, 2);
|
||||
packet.physicalId = getDataId(luaL_checkinteger(L, 1));
|
||||
packet.primId = luaL_checkinteger(L, 2);
|
||||
packet.dataId = dataId;
|
||||
packet.value = luaL_checkunsigned(L, 4);
|
||||
packet.value = luaL_checkinteger(L, 4);
|
||||
outputTelemetryBuffer.pushSportPacketWithBytestuffing(packet);
|
||||
#if defined(PXX2) && defined(HARDWARE_EXTERNAL_MODULE)
|
||||
uint8_t destination = (intmod ? INTERNAL_MODULE : EXTERNAL_MODULE);
|
||||
@@ -1101,7 +1101,7 @@ static int luaAccessTelemetryPush(lua_State * L)
|
||||
|
||||
if (outputTelemetryBuffer.isAvailable()) {
|
||||
int8_t module = luaL_checkinteger(L, 1);
|
||||
uint8_t rxUid = luaL_checkunsigned(L, 2);
|
||||
uint8_t rxUid = luaL_checkinteger(L, 2);
|
||||
uint8_t destination;
|
||||
|
||||
if (module < 0) {
|
||||
@@ -1114,10 +1114,10 @@ static int luaAccessTelemetryPush(lua_State * L)
|
||||
destination = (module << 2) + rxUid;
|
||||
}
|
||||
|
||||
outputTelemetryBuffer.sport.physicalId = getDataId(luaL_checkunsigned(L, 3));
|
||||
outputTelemetryBuffer.sport.primId = luaL_checkunsigned(L, 4);
|
||||
outputTelemetryBuffer.sport.dataId = luaL_checkunsigned(L, 5);
|
||||
outputTelemetryBuffer.sport.value = luaL_checkunsigned(L, 6);
|
||||
outputTelemetryBuffer.sport.physicalId = getDataId(luaL_checkinteger(L, 3));
|
||||
outputTelemetryBuffer.sport.primId = luaL_checkinteger(L, 4);
|
||||
outputTelemetryBuffer.sport.dataId = luaL_checkinteger(L, 5);
|
||||
outputTelemetryBuffer.sport.value = luaL_checkinteger(L, 6);
|
||||
outputTelemetryBuffer.setDestination(destination);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
@@ -1156,7 +1156,7 @@ static int luaCrossfireTelemetryPop(lua_State * L)
|
||||
// length value includes the length field
|
||||
luaInputTelemetryFifo->pop(length);
|
||||
luaInputTelemetryFifo->pop(data); // command
|
||||
lua_pushnumber(L, data);
|
||||
lua_pushinteger(L, data);
|
||||
lua_newtable(L);
|
||||
for (uint8_t i=1; i<length-1; i++) {
|
||||
luaInputTelemetryFifo->pop(data);
|
||||
@@ -1205,7 +1205,7 @@ static int luaCrossfireTelemetryPush(lua_State* L)
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
} else if (outputTelemetryBuffer.isAvailable()) {
|
||||
uint8_t command = luaL_checkunsigned(L, 1);
|
||||
uint8_t command = luaL_checkinteger(L, 1);
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
uint8_t length = luaL_len(L, 2);
|
||||
|
||||
@@ -1226,7 +1226,7 @@ static int luaCrossfireTelemetryPush(lua_State* L)
|
||||
// PAYLOAD
|
||||
for (int i = 0; i < length; i++) {
|
||||
lua_rawgeti(L, 2, i + 1);
|
||||
outputTelemetryBuffer.pushByte(luaL_checkunsigned(L, -1));
|
||||
outputTelemetryBuffer.pushByte(luaL_checkinteger(L, -1));
|
||||
}
|
||||
|
||||
// CRC
|
||||
@@ -1280,7 +1280,7 @@ static int luaGhostTelemetryPop(lua_State * L)
|
||||
// length value includes type(1B), payload, crc(1B)
|
||||
luaInputTelemetryFifo->pop(length);
|
||||
luaInputTelemetryFifo->pop(data); // type
|
||||
lua_pushnumber(L, data); // return type
|
||||
lua_pushinteger(L, data); // return type
|
||||
lua_newtable(L);
|
||||
for (uint8_t i=0; i<length-2; i++) {
|
||||
luaInputTelemetryFifo->pop(data);
|
||||
@@ -1327,7 +1327,7 @@ static int luaGhostTelemetryPush(lua_State * L)
|
||||
return 1;
|
||||
}
|
||||
else if (outputTelemetryBuffer.isAvailable()) {
|
||||
uint8_t type = luaL_checkunsigned(L, 1);
|
||||
uint8_t type = luaL_checkinteger(L, 1);
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
uint8_t length = luaL_len(L, 2); // payload length
|
||||
|
||||
@@ -1343,7 +1343,7 @@ static int luaGhostTelemetryPush(lua_State * L)
|
||||
int i = 0;
|
||||
for (; i < length; i++) { // data, max 10B
|
||||
lua_rawgeti(L, 2, i + 1);
|
||||
outputTelemetryBuffer.pushByte(luaL_checkunsigned(L, -1));
|
||||
outputTelemetryBuffer.pushByte(luaL_checkinteger(L, -1));
|
||||
}
|
||||
for (; i < 10; i++) { // fill zeroes to frame size
|
||||
outputTelemetryBuffer.pushByte(0);
|
||||
@@ -1442,7 +1442,7 @@ static int luaGetFlightMode(lua_State * L)
|
||||
if (mode < 0 || mode >= MAX_FLIGHT_MODES) {
|
||||
mode = mixerCurrentFlightMode;
|
||||
}
|
||||
lua_pushnumber(L, mode);
|
||||
lua_pushinteger(L, mode);
|
||||
char name[sizeof(g_model.flightModeData[0].name)+1];
|
||||
strncpy(name, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[0].name));
|
||||
name[sizeof(g_model.flightModeData[0].name)] = '\0';
|
||||
@@ -1530,7 +1530,7 @@ static int luaPlayNumber(lua_State * L)
|
||||
{
|
||||
int number = luaL_checkinteger(L, 1);
|
||||
int unit = luaL_checkinteger(L, 2);
|
||||
unsigned int att = luaL_optunsigned(L, 3, 0);
|
||||
unsigned int att = luaL_optinteger(L, 3, 0);
|
||||
int volume = luaL_optinteger(L, 4, USE_SETTINGS_VOLUME);
|
||||
|
||||
if(volume != USE_SETTINGS_VOLUME)
|
||||
@@ -1729,7 +1729,7 @@ Returns gray value which can be used in LCD functions
|
||||
static int luaGrey(lua_State * L)
|
||||
{
|
||||
int index = luaL_checkinteger(L, 1);
|
||||
lua_pushunsigned(L, GREY(index));
|
||||
lua_pushinteger(L, GREY(index));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
@@ -2001,12 +2001,12 @@ must be different from zero.
|
||||
*/
|
||||
static int luaSetTelemetryValue(lua_State * L)
|
||||
{
|
||||
uint16_t id = luaL_checkunsigned(L, 1);
|
||||
uint8_t subId = luaL_checkunsigned(L, 2) & 0x7;
|
||||
uint8_t instance = luaL_checkunsigned(L, 3);
|
||||
uint16_t id = luaL_checkinteger(L, 1);
|
||||
uint8_t subId = luaL_checkinteger(L, 2) & 0x7;
|
||||
uint8_t instance = luaL_checkinteger(L, 3);
|
||||
int32_t value = luaL_checkinteger(L, 4);
|
||||
uint32_t unit = luaL_optunsigned(L, 5, 0);
|
||||
uint32_t prec = luaL_optunsigned(L, 6, 0);
|
||||
uint32_t unit = luaL_optinteger(L, 5, 0);
|
||||
uint32_t prec = luaL_optinteger(L, 6, 0);
|
||||
|
||||
char name_buf[TELEM_LABEL_LEN]; // 4
|
||||
const char* name = luaL_optstring(L, 7, NULL);
|
||||
@@ -2094,11 +2094,11 @@ Get RSSI value as well as low and critical RSSI alarm levels (in dB)
|
||||
static int luaGetRSSI(lua_State * L)
|
||||
{
|
||||
if (TELEMETRY_STREAMING())
|
||||
lua_pushunsigned(L, min((uint8_t)99, TELEMETRY_RSSI()));
|
||||
lua_pushinteger(L, min((uint8_t)99, TELEMETRY_RSSI()));
|
||||
else
|
||||
lua_pushunsigned(L, 0);
|
||||
lua_pushunsigned(L, g_model.rfAlarms.warning);
|
||||
lua_pushunsigned(L, g_model.rfAlarms.critical);
|
||||
lua_pushinteger(L, 0);
|
||||
lua_pushinteger(L, g_model.rfAlarms.warning);
|
||||
lua_pushinteger(L, g_model.rfAlarms.critical);
|
||||
return 3;
|
||||
}
|
||||
|
||||
@@ -2213,7 +2213,7 @@ Get available memory remaining in the Heap for Lua.
|
||||
*/
|
||||
static int luaGetAvailableMemory(lua_State * L)
|
||||
{
|
||||
lua_pushunsigned(L, availableMemory());
|
||||
lua_pushinteger(L, availableMemory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2273,7 +2273,7 @@ uint8_t * Multi_Buffer = nullptr;
|
||||
|
||||
static int luaMultiBuffer(lua_State * L)
|
||||
{
|
||||
uint8_t address = luaL_checkunsigned(L, 1);
|
||||
uint8_t address = luaL_checkinteger(L, 1);
|
||||
if (!Multi_Buffer)
|
||||
Multi_Buffer = (uint8_t *) malloc(MULTI_BUFFER_SIZE);
|
||||
|
||||
@@ -2281,7 +2281,7 @@ static int luaMultiBuffer(lua_State * L)
|
||||
lua_pushinteger(L, 0);
|
||||
return 0;
|
||||
}
|
||||
uint16_t value = luaL_optunsigned(L, 2, 0x100);
|
||||
uint16_t value = luaL_optinteger(L, 2, 0x100);
|
||||
if (value < 0x100) {
|
||||
Multi_Buffer[address] = value;
|
||||
}
|
||||
@@ -2352,7 +2352,7 @@ Reads characters from the serial port. The string is allowed to contain any char
|
||||
*/
|
||||
static int luaSerialRead(lua_State * L)
|
||||
{
|
||||
int num = luaL_optunsigned(L, 1, 0);
|
||||
int num = luaL_optinteger(L, 1, 0);
|
||||
|
||||
uint8_t str[LUA_FIFO_SIZE];
|
||||
uint8_t *p = str;
|
||||
@@ -2401,7 +2401,7 @@ static int luaSerialRead(lua_State * L)
|
||||
*/
|
||||
static int luaSerialGetPower(lua_State* L)
|
||||
{
|
||||
uint8_t port_nr = luaL_checkunsigned(L, 1) & 0x3;
|
||||
uint8_t port_nr = luaL_checkinteger(L, 1) & 0x3;
|
||||
|
||||
#if defined(AUX_SERIAL)
|
||||
if (port_nr == SP_AUX1)
|
||||
@@ -2439,8 +2439,8 @@ static int luaSerialGetPower(lua_State* L)
|
||||
*/
|
||||
static int luaSerialSetPower(lua_State* L)
|
||||
{
|
||||
uint8_t port_nr = luaL_checkunsigned(L, 1) & 0x3;
|
||||
uint8_t value = luaL_checkunsigned(L, 2) & 0x3;
|
||||
uint8_t port_nr = luaL_checkinteger(L, 1) & 0x3;
|
||||
uint8_t value = luaL_checkinteger(L, 2) & 0x3;
|
||||
|
||||
if (value < 2)
|
||||
{
|
||||
|
||||
+38
-36
@@ -30,6 +30,8 @@
|
||||
#include "gvars.h"
|
||||
#include "mixes.h"
|
||||
|
||||
#include "lua_states.h"
|
||||
|
||||
#include <storage/sdcard_yaml.h>
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
@@ -100,7 +102,7 @@ static int luaModelSetInfo(lua_State *L)
|
||||
g_model.extendedLimits = lua_toboolean(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "jitterFilter")) {
|
||||
auto j = lua_tounsigned(L, -1);
|
||||
auto j = lua_tointeger(L, -1);
|
||||
if (j > OVERRIDE_ON) j = OVERRIDE_ON;
|
||||
g_model.jitterFilter = j;
|
||||
}
|
||||
@@ -162,7 +164,7 @@ Get RF module parameters
|
||||
*/
|
||||
static int luaModelGetModule(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < NUM_MODULES) {
|
||||
ModuleData & module = g_model.moduleData[idx];
|
||||
lua_newtable(L);
|
||||
@@ -211,7 +213,7 @@ that parameter remains unchanged.
|
||||
*/
|
||||
static int luaModelSetModule(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
|
||||
if (idx < NUM_MODULES) {
|
||||
int protocol = -1;
|
||||
@@ -283,7 +285,7 @@ Get model timer parameters
|
||||
*/
|
||||
static int luaModelGetTimer(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_TIMERS) {
|
||||
TimerData & timer = g_model.timers[idx];
|
||||
lua_newtable(L);
|
||||
@@ -321,7 +323,7 @@ that parameter remains unchanged.
|
||||
*/
|
||||
static int luaModelSetTimer(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
|
||||
if (idx < MAX_TIMERS) {
|
||||
TimerData & timer = g_model.timers[idx];
|
||||
@@ -380,7 +382,7 @@ Reset model timer to a startup value
|
||||
*/
|
||||
static int luaModelResetTimer(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_TIMERS) {
|
||||
timerReset(idx);
|
||||
}
|
||||
@@ -427,7 +429,7 @@ Return number of lines for given input
|
||||
*/
|
||||
static int luaModelGetInputsCount(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
int count = getInputsCount(chn);
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
@@ -471,7 +473,7 @@ Return input data for given input and line number
|
||||
*/
|
||||
static int luaModelGetFlightMode(lua_State * L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_FLIGHT_MODES) {
|
||||
FlightModeData * fm = flightModeAddress(idx);
|
||||
lua_newtable(L);
|
||||
@@ -515,7 +517,7 @@ Set Flight mode parameters
|
||||
*/
|
||||
static int luaModelSetFlightMode(lua_State * L)
|
||||
{
|
||||
unsigned int flightMode = luaL_checkunsigned(L, 1);
|
||||
unsigned int flightMode = luaL_checkinteger(L, 1);
|
||||
|
||||
if (flightMode >= MAX_FLIGHT_MODES) {
|
||||
lua_pushinteger(L, 2);
|
||||
@@ -599,8 +601,8 @@ Return input data for given input and line number
|
||||
*/
|
||||
static int luaModelGetInput(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
unsigned int first = getFirstInput(chn);
|
||||
unsigned int count = getInputsCountFromFirst(chn, first);
|
||||
if (idx < count) {
|
||||
@@ -639,8 +641,8 @@ Insert an Input at specified line
|
||||
*/
|
||||
static int luaModelInsertInput(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
|
||||
unsigned int first = getFirstInput(chn);
|
||||
unsigned int count = getInputsCountFromFirst(chn, first);
|
||||
@@ -724,8 +726,8 @@ Delete line from specified input
|
||||
*/
|
||||
static int luaModelDeleteInput(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
|
||||
int first = getFirstInput(chn);
|
||||
unsigned int count = getInputsCountFromFirst(chn, first);
|
||||
@@ -804,7 +806,7 @@ Get the number of Mixer lines that the specified Channel has
|
||||
*/
|
||||
static int luaModelGetMixesCount(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int count = getMixesCount(chn);
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
@@ -842,8 +844,8 @@ Get configuration for specified Mix
|
||||
*/
|
||||
static int luaModelGetMix(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
unsigned int first = getFirstMix(chn);
|
||||
unsigned int count = getMixesCountFromFirst(chn, first);
|
||||
if (idx < count) {
|
||||
@@ -886,8 +888,8 @@ Insert a mixer line into Channel
|
||||
*/
|
||||
static int luaModelInsertMix(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
|
||||
unsigned int first = getFirstMix(chn);
|
||||
unsigned int count = getMixesCountFromFirst(chn, first);
|
||||
@@ -977,8 +979,8 @@ Delete mixer line from specified Channel
|
||||
*/
|
||||
static int luaModelDeleteMix(lua_State *L)
|
||||
{
|
||||
unsigned int chn = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkunsigned(L, 2);
|
||||
unsigned int chn = luaL_checkinteger(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 2);
|
||||
|
||||
unsigned int first = getFirstMix(chn);
|
||||
unsigned int count = getMixesCountFromFirst(chn, first);
|
||||
@@ -1025,7 +1027,7 @@ Get Logical Switch parameters
|
||||
*/
|
||||
static int luaModelGetLogicalSwitch(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_LOGICAL_SWITCHES) {
|
||||
LogicalSwitchData * sw = lswAddress(idx);
|
||||
lua_newtable(L);
|
||||
@@ -1062,7 +1064,7 @@ use the following syntax: `model.setLogicalSwitch(30, {func=4,v1=1,v2=-99, ["and
|
||||
*/
|
||||
static int luaModelSetLogicalSwitch(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_LOGICAL_SWITCHES) {
|
||||
LogicalSwitchData * sw = lswAddress(idx);
|
||||
memclear(sw, sizeof(LogicalSwitchData));
|
||||
@@ -1126,7 +1128,7 @@ Get Curve parameters
|
||||
*/
|
||||
static int luaModelGetCurve(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_CURVES) {
|
||||
CurveHeader & CurveHeader = g_model.curves[idx];
|
||||
lua_newtable(L);
|
||||
@@ -1207,7 +1209,7 @@ setting a 6-point standard smoothed curve
|
||||
*/
|
||||
static int luaModelSetCurve(lua_State *L)
|
||||
{
|
||||
unsigned int curveIdx = luaL_checkunsigned(L, 1);
|
||||
unsigned int curveIdx = luaL_checkinteger(L, 1);
|
||||
|
||||
if (curveIdx >= MAX_CURVES) {
|
||||
lua_pushinteger(L, 2);
|
||||
@@ -1382,7 +1384,7 @@ Get Custom Function parameters
|
||||
*/
|
||||
static int luaModelGetCustomFunction(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_SPECIAL_FUNCTIONS) {
|
||||
CustomFunctionData * cfn = &g_model.customFn[idx];
|
||||
lua_newtable(L);
|
||||
@@ -1421,7 +1423,7 @@ that parameter remains unchanged.
|
||||
*/
|
||||
static int luaModelSetCustomFunction(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_SPECIAL_FUNCTIONS) {
|
||||
CustomFunctionData * cfn = &g_model.customFn[idx];
|
||||
memclear(cfn, sizeof(CustomFunctionData));
|
||||
@@ -1486,7 +1488,7 @@ Get servo parameters
|
||||
*/
|
||||
static int luaModelGetOutput(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_OUTPUT_CHANNELS) {
|
||||
LimitData * limit = limitAddress(idx);
|
||||
lua_newtable(L);
|
||||
@@ -1522,7 +1524,7 @@ that parameter remains unchanged.
|
||||
*/
|
||||
static int luaModelSetOutput(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_OUTPUT_CHANNELS) {
|
||||
LimitData * limit = limitAddress(idx);
|
||||
memclear(limit, sizeof(LimitData));
|
||||
@@ -1587,8 +1589,8 @@ Example:
|
||||
*/
|
||||
static int luaModelGetGlobalVariable(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int phase = luaL_checkunsigned(L, 2);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
unsigned int phase = luaL_checkinteger(L, 2);
|
||||
if (phase < MAX_FLIGHT_MODES && idx < MAX_GVARS)
|
||||
lua_pushinteger(L, getGVarValue(idx, phase));
|
||||
else
|
||||
@@ -1614,8 +1616,8 @@ by truncating everything behind a floating point.
|
||||
*/
|
||||
static int luaModelSetGlobalVariable(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int phase = luaL_checkunsigned(L, 2);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
unsigned int phase = luaL_checkinteger(L, 2);
|
||||
int value = luaL_checkinteger(L, 3);
|
||||
if (phase < MAX_FLIGHT_MODES && idx < MAX_GVARS && value >= -GVAR_MAX && value <= GVAR_MAX) {
|
||||
SET_GVAR(idx, value, phase);
|
||||
@@ -1722,7 +1724,7 @@ Get Telemetry Sensor parameters
|
||||
*/
|
||||
static int luaModelGetSensor(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_TELEMETRY_SENSORS) {
|
||||
TelemetrySensor & sensor = g_model.telemetrySensors[idx];
|
||||
lua_newtable(L);
|
||||
@@ -1757,7 +1759,7 @@ Reset Telemetry Sensor parameters
|
||||
*/
|
||||
static int luaModelResetSensor(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
unsigned int idx = luaL_checkinteger(L, 1);
|
||||
if (idx < MAX_TELEMETRY_SENSORS) {
|
||||
telemetryItems[idx].clear();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <cstdio>
|
||||
#include "edgetx.h"
|
||||
#include "lua_api.h"
|
||||
#include "lua_states.h"
|
||||
|
||||
/*luadoc
|
||||
@function lcd.refresh()
|
||||
|
||||
@@ -276,6 +276,15 @@ void luaClose(lua_State ** L)
|
||||
}
|
||||
}
|
||||
|
||||
void luaClose()
|
||||
{
|
||||
#if defined(COLORLCD)
|
||||
luaClose(&lsWidgets);
|
||||
extern lua_State* lsStandalone;
|
||||
luaClose(&lsStandalone);
|
||||
#endif
|
||||
luaClose(&lsScripts);
|
||||
}
|
||||
|
||||
void luaRegisterLibraries(lua_State * L)
|
||||
{
|
||||
@@ -629,10 +638,12 @@ static bool luaLoad(const char * pathname, ScriptInternalData & sid)
|
||||
|
||||
template<unsigned int LD, unsigned int LF>
|
||||
static bool luaLoadFile(const char (&dirname)[LD], const char (&filename)[LF], ScriptInternalData & sid) {
|
||||
constexpr size_t maxlen{LD + LF + (sizeof(SCRIPT_EXT) - 1) + 1 + 1}; // iff dirname is string-literal (LD includes '\0') this is one byte too large, but with C++11 there is no chance to check if dirname is a literal or a (maybe-unterminated) char-array
|
||||
char pathname[maxlen];
|
||||
snprintf(pathname, maxlen, "%.*s/%.*s%s", LD, dirname, LF, filename, SCRIPT_EXT);
|
||||
return luaLoad(pathname, sid);
|
||||
// iff dirname is string-literal (LD includes '\0') this is one byte too large,
|
||||
// but with C++11 there is no chance to check if dirname is a literal or a (maybe-unterminated) char-array
|
||||
constexpr size_t maxlen{LD + LF + (sizeof(SCRIPT_EXT) - 1) + 1 + 1};
|
||||
char pathname[maxlen];
|
||||
snprintf(pathname, maxlen, "%.*s/%.*s%s", LD, dirname, LF, filename, SCRIPT_EXT);
|
||||
return luaLoad(pathname, sid);
|
||||
}
|
||||
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
@@ -1015,6 +1026,8 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
|
||||
|
||||
} // luaLoadScripts
|
||||
|
||||
void luaGetValueAndPush(lua_State *L, int src);
|
||||
|
||||
void luaExec(const char * filename)
|
||||
{
|
||||
luaState = INTERPRETER_LOADING;
|
||||
@@ -1086,7 +1099,7 @@ static bool resumeLua(bool init, bool allowLcdUsage)
|
||||
luaNextEvent(&evt);
|
||||
|
||||
lua_rawgeti(lsScripts, LUA_REGISTRYINDEX, sid.run);
|
||||
lua_pushunsigned(lsScripts, evt.event);
|
||||
lua_pushinteger(lsScripts, evt.event);
|
||||
inputsCount = 1;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
@@ -1345,7 +1358,7 @@ void luaInit()
|
||||
lsScriptsTrace.script = "lua_newstate(scripts)";
|
||||
L = lua_newstate(tracer_alloc, &lsScriptsTrace); //we use tracer allocator
|
||||
#else
|
||||
L = lua_newstate(l_alloc, nullptr); //we use Lua default allocator
|
||||
L = luaL_newstate(); //we use Lua default allocator
|
||||
#endif
|
||||
if (L) {
|
||||
// install our panic handler
|
||||
|
||||
+4
-17
@@ -27,11 +27,8 @@
|
||||
#include "rtos.h"
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include <lgc.h>
|
||||
}
|
||||
#include "lua.h"
|
||||
};
|
||||
|
||||
#include "dataconstants.h"
|
||||
#include "edgetx_types.h"
|
||||
@@ -55,7 +52,6 @@ void luaReceiveData(uint8_t* buf, uint32_t len);
|
||||
void luaSetSendCb(void* ctx, void (*cb)(void*, uint8_t));
|
||||
void luaSetGetSerialByte(void* ctx, int (*fct)(void*, uint8_t*));
|
||||
|
||||
extern lua_State * lsScripts;
|
||||
|
||||
extern bool luaLcdAllowed;
|
||||
|
||||
@@ -71,12 +67,13 @@ extern LuaWidget* runningFS;
|
||||
class LuaLvglManager;
|
||||
extern LuaLvglManager* luaLvglManager;
|
||||
|
||||
extern lua_State* lsWidgets;
|
||||
extern uint32_t luaExtraMemoryUsage;
|
||||
void luaInitThemesAndWidgets();
|
||||
#endif
|
||||
|
||||
void luaInit();
|
||||
void luaClose();
|
||||
|
||||
void luaEmptyEventBuffer();
|
||||
|
||||
#define lua_registernumber(L, n, i) (lua_pushnumber(L, (i)), lua_setglobal(L, (n)))
|
||||
@@ -182,13 +179,9 @@ extern bool luaLcdAllowed;
|
||||
extern ScriptInternalData scriptInternalData[MAX_SCRIPTS];
|
||||
extern ScriptInputsOutputs scriptInputsOutputs[MAX_SCRIPTS];
|
||||
|
||||
void luaClose(lua_State ** L);
|
||||
bool luaTask(bool allowLcdUsage);
|
||||
void checkLuaMemoryUsage();
|
||||
void luaExec(const char * filename);
|
||||
void luaDoGc(lua_State * L, bool full);
|
||||
uint32_t luaGetMemUsed(lua_State * L);
|
||||
void luaGetValueAndPush(lua_State * L, int src);
|
||||
bool isTelemetryScriptAvailable();
|
||||
|
||||
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
|
||||
@@ -225,12 +218,6 @@ struct LuaField {
|
||||
bool luaFindFieldByName(const char * name, LuaField & field, unsigned int flags=0);
|
||||
bool luaFindFieldById(int id, LuaField & field, unsigned int flags=0);
|
||||
void luaLoadThemes();
|
||||
void luaRegisterLibraries(lua_State * L);
|
||||
void registerBitmapClass(lua_State * L);
|
||||
void luaSetInstructionsLimit(lua_State* L, int count);
|
||||
int luaLoadScriptFileToState(lua_State * L, const char * filename, const char * mode);
|
||||
void luaPushDateTime(lua_State * L, uint32_t year, uint32_t mon, uint32_t day,
|
||||
uint32_t hour, uint32_t min, uint32_t sec);
|
||||
|
||||
// Unregister LUA widget factories
|
||||
void luaUnregisterWidgets();
|
||||
|
||||
@@ -31,8 +31,7 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static int pcallcont (lua_State *L) {
|
||||
int status = lua_getctx(L, NULL);
|
||||
static int pcallcont (lua_State *L, int status, lua_KContext extra) {
|
||||
return status == LUA_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
EXTERN_C_START
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
#include "lgc.h"
|
||||
EXTERN_C_END
|
||||
|
||||
// #define LUA_INIT_THEMES_AND_WIDGETS() luaInitThemesAndWidgets()
|
||||
// #define lua_registernumber(L, n, i) (lua_pushnumber(L, (i)), lua_setglobal(L, (n)))
|
||||
// #define lua_registerint(L, n, i) (lua_pushinteger(L, (i)), lua_setglobal(L, (n)))
|
||||
|
||||
#define lua_pushtableboolean(L, k, v) \
|
||||
(lua_pushstring(L, (k)), lua_pushboolean(L, (v)), lua_settable(L, -3))
|
||||
|
||||
#define lua_pushtableinteger(L, k, v) \
|
||||
(lua_pushstring(L, (k)), lua_pushinteger(L, (v)), lua_settable(L, -3))
|
||||
|
||||
#define lua_pushtablenumber(L, k, v) \
|
||||
(lua_pushstring(L, (k)), lua_pushnumber(L, (v)), lua_settable(L, -3))
|
||||
|
||||
// size based string (possibly no null-termination)
|
||||
#define __lua_strncpy(s) \
|
||||
char tmp[sizeof(s) + 1]; \
|
||||
strncpy(tmp, (s), sizeof(tmp) - 1); \
|
||||
tmp[sizeof(s)] = '\0';
|
||||
|
||||
// size based string (possibly no null-termination)
|
||||
#define lua_pushnstring(L, s) \
|
||||
{ \
|
||||
__lua_strncpy(s); \
|
||||
lua_pushstring(L, tmp); \
|
||||
}
|
||||
#define lua_pushtablenstring(L, k, v) \
|
||||
{ \
|
||||
__lua_strncpy(v); \
|
||||
lua_pushstring(L, (k)); \
|
||||
lua_pushstring(L, tmp); \
|
||||
lua_settable(L, -3); \
|
||||
}
|
||||
|
||||
// null-terminated string
|
||||
#define lua_pushtablestring(L, k, v) \
|
||||
(lua_pushstring(L, (k)), lua_pushstring(L, (v)), lua_settable(L, -3))
|
||||
|
||||
// #define lua_registerlib(L, name, tab) (luaL_newmetatable(L, name), luaL_setfuncs(L, tab, 0), lua_setglobal(L, name))
|
||||
|
||||
extern lua_State* lsScripts;
|
||||
extern lua_State* lsWidgets;
|
||||
|
||||
void luaSetInstructionsLimit(lua_State* L, int count);
|
||||
int luaLoadScriptFileToState(lua_State * L, const char * filename, const char * mode);
|
||||
void luaRegisterLibraries(lua_State * L);
|
||||
void luaClose(lua_State ** L);
|
||||
void luaDoGc(lua_State * L, bool full);
|
||||
uint32_t luaGetMemUsed(lua_State * L);
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "lua_api.h"
|
||||
#include "lua_event.h"
|
||||
#include "lua_widget_factory.h"
|
||||
#include "lua_states.h"
|
||||
|
||||
#include "touch.h"
|
||||
#include "view_main.h"
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "window.h"
|
||||
#include "widget.h"
|
||||
#include "lua_states.h"
|
||||
#include "lua_api.h"
|
||||
#include "lua_lvgl_widget.h"
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "lua_widget.h"
|
||||
|
||||
#include "lua_api.h"
|
||||
#include "lua_states.h"
|
||||
|
||||
#define MAX_INSTRUCTIONS (20000/100)
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "lua_widget.h"
|
||||
#include "lua_widget_factory.h"
|
||||
|
||||
#include "lua_states.h"
|
||||
|
||||
#define MAX_INSTRUCTIONS (20000/100)
|
||||
#define LUA_WARNING_INFO_LEN 64
|
||||
|
||||
@@ -348,7 +350,7 @@ void luaInitThemesAndWidgets()
|
||||
lsWidgetsTrace.script = "lua_newstate(widgets)";
|
||||
lsWidgets = lua_newstate(tracer_alloc, &lsWidgetsTrace); //we use tracer allocator
|
||||
#else
|
||||
lsWidgets = lua_newstate(l_alloc, NULL); //we use Lua default allocator
|
||||
lsWidgets = luaL_newstate(); //we use Lua default allocator
|
||||
#endif
|
||||
if (lsWidgets) {
|
||||
// install our panic handler
|
||||
|
||||
Reference in New Issue
Block a user