From 829567a2c18e59561e778662111b410fb185d83a Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 15 Sep 2014 17:32:45 +0200 Subject: [PATCH] #1647 - getCurve exported to the Lua interpreter --- radio/src/lua.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ radio/src/lua/src/lapi.c | 17 +++++++++++--- radio/src/myeeprom.h | 4 ++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 29a8eb9d1..1b47572c4 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -810,6 +810,8 @@ static int luaModelGetMix(lua_State *L) lua_pushtableinteger(L, "weight", mix->weight); lua_pushtableinteger(L, "offset", mix->offset); lua_pushtableinteger(L, "switch", mix->swtch); + lua_pushtableinteger(L, "curveType", mix->curve.type); + lua_pushtableinteger(L, "curveValue", mix->curve.value); lua_pushtableinteger(L, "multiplex", mix->mltpx); } else { @@ -851,6 +853,12 @@ static int luaModelInsertMix(lua_State *L) else if (!strcmp(key, "switch")) { mix->swtch = luaL_checkinteger(L, -1); } + else if (!strcmp(key, "curveType")) { + mix->curve.type = luaL_checkinteger(L, -1); + } + else if (!strcmp(key, "curveValue")) { + mix->curve.value = luaL_checkinteger(L, -1); + } else if (!strcmp(key, "multiplex")) { mix->mltpx = luaL_checkinteger(L, -1); } @@ -939,6 +947,48 @@ static int luaModelSetLogicalSwitch(lua_State *L) return 0; } +static int luaModelGetCurve(lua_State *L) +{ + int idx = luaL_checkunsigned(L, 1); + if (idx < MAX_CURVES) { + CurveInfo & curveInfo = g_model.curves[idx]; + lua_newtable(L); + lua_pushtablezstring(L, "name", g_model.curveNames[idx]); + lua_pushtableinteger(L, "type", curveInfo.type); + lua_pushtableboolean(L, "smooth", curveInfo.smooth); + lua_pushtableinteger(L, "points", curveInfo.points+5); + lua_pushstring(L, "y"); + lua_newtable(L); + int8_t * point = curveAddress(idx); + for (int i=0; il_registry); const TValue *gt; /* global table */ lua_lock(L); - 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); + + lu_byte keytype; + luaR_result res = luaR_findglobal(var, &keytype); + if (res != 0) { + setsvalue2s(L, L->top++, luaS_new(L, var)); + setlfvalue(L->top - 1, (void*)(size_t)res) + } + 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); + } + lua_unlock(L); } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index c9e67d67f..e24fcfaf6 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -171,7 +171,7 @@ CURVE_TYPE_CUSTOM, CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM }; -PACK(typedef struct t_CurveInfo { +PACK(typedef struct { uint8_t type:3; uint8_t smooth:1; uint8_t spare:4; @@ -479,7 +479,7 @@ enum CurveRefType { CURVE_REF_FUNC, CURVE_REF_CUSTOM }; -PACK(typedef struct t_CurveRef { +PACK(typedef struct { uint8_t type; int8_t value; }) CurveRef;