From 36409c37f49eee9ccdb2c90c67e772566dacd55d Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Mon, 21 Apr 2014 17:21:02 +0200 Subject: [PATCH 1/4] SOURCE type input for model scripts missing getValue() --- radio/src/lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index fd2ec873f..6677e0c62 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -1064,7 +1064,7 @@ void luaTask(uint8_t evt) lua_rawgeti(L, LUA_REGISTRYINDEX, sid.run); for (int j=0; j Date: Mon, 21 Apr 2014 20:17:30 +0200 Subject: [PATCH 2/4] Return nil if value not found in luaGetValue() --- radio/src/lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 6677e0c62..f97e6618f 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -131,7 +131,7 @@ static int luaGetValue(lua_State *L) return 1; } } - + lua_pushnil(L); return 0; } From cfa25ab030eb88c44416cd7f43cfcd8532399bda Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Mon, 21 Apr 2014 20:26:23 +0200 Subject: [PATCH 3/4] Bad indentation --- radio/src/lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index f97e6618f..75e571e3d 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -131,7 +131,7 @@ static int luaGetValue(lua_State *L) return 1; } } - lua_pushnil(L); + lua_pushnil(L); return 0; } From d9c1bf767fb3ee7f30f498ae6f7ce77deccbb7d1 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Mon, 21 Apr 2014 20:47:38 +0200 Subject: [PATCH 4/4] Refactored luaGetValue(), my previous fix was incorrect. --- radio/src/lua.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 75e571e3d..34b225650 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -102,36 +102,25 @@ static int luaGetValue(lua_State *L) lua_pushnumber(L, double(frskyData.hub.baroAltitude)/100); return 1; } - else if (!strcmp(what, "latitude")) { - if (frskyData.hub.gpsFix) + else if (frskyData.hub.gpsFix) { + if (!strcmp(what, "latitude")) { lua_pushnumber(L, gpsToDouble(frskyData.hub.gpsLatitudeNS=='S', frskyData.hub.gpsLatitude_bp, frskyData.hub.gpsLatitude_ap)); - else - lua_pushnil(L); - return 1; - } - else if (!strcmp(what, "longitude")) { - if (frskyData.hub.gpsFix) + return 1; + } + else if (!strcmp(what, "longitude")) { lua_pushnumber(L, gpsToDouble(frskyData.hub.gpsLongitudeEW=='W', frskyData.hub.gpsLongitude_bp, frskyData.hub.gpsLongitude_ap)); - else - lua_pushnil(L); - return 1; - } - else if (!strcmp(what, "pilot latitude")) { - if (frskyData.hub.gpsFix) + return 1; + } + else if (!strcmp(what, "pilot latitude")) { lua_pushnumber(L, pilotLatitude); - else - lua_pushnil(L); - return 1; - } - else if (!strcmp(what, "pilot longitude")) { - if (frskyData.hub.gpsFix) + return 1; + } + else if (!strcmp(what, "pilot longitude")) { lua_pushnumber(L, pilotLongitude); - else - lua_pushnil(L); - return 1; + return 1; + } } } - lua_pushnil(L); return 0; }