From e1b13426552adadbf324e91c5430f711f340c4d8 Mon Sep 17 00:00:00 2001 From: "David S. Beach" Date: Thu, 3 Sep 2015 14:41:18 -0400 Subject: [PATCH] using pre-allocated table space via lua_createtable() for GPS, DATETIME, and CELLS --- radio/src/lua_api.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/radio/src/lua_api.cpp b/radio/src/lua_api.cpp index fd1d94b47..246d69a1d 100644 --- a/radio/src/lua_api.cpp +++ b/radio/src/lua_api.cpp @@ -119,7 +119,7 @@ static int luaGetTime(lua_State *L) static void luaPushDateTime(lua_State *L, uint32_t year, uint32_t mon, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec) { - lua_newtable(L); + lua_createtable(L, 0, 6); lua_pushtableinteger(L, "year", year); lua_pushtableinteger(L, "mon", mon); lua_pushtableinteger(L, "day", day); @@ -150,7 +150,7 @@ static void luaPushLatLon(TelemetrySensor & telemetrySensor, TelemetryItem & tel lon = gpsLon / 1000000.0; if (telemetryItem.gps.longitudeEW == 'W') lon = -lon; - lua_newtable(L); + lua_createtable(L, 0, 2); lua_pushtablenumber(L, "lat", lat); lua_pushtablenumber(L, "lon", lon); } @@ -166,7 +166,7 @@ static void luaPushCells(TelemetrySensor & telemetrySensor, TelemetryItem & tele if (telemetryItem.cells.count == 0) lua_pushinteger(L, (int)0); // returns zero if no cells else { - lua_createtable(L, 0 /*telemetryItem.cells.count*/, 0); + lua_createtable(L, telemetryItem.cells.count, 0); for (int i = 0; i < telemetryItem.cells.count; i++) { lua_pushnumber(L, i + 1); lua_pushnumber(L, telemetryItem.cells.values[i].value / 100.0);