From 87e1abfb0f12eacebba981b6eed40b8f1a67d34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Sun, 22 Jan 2017 20:17:46 +0100 Subject: [PATCH] rtctime: change to lua_setfieldfor populating the table (#1746) Looks good. --- app/modules/rtctime.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index a48d216c..b6558e5f 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -180,12 +180,9 @@ static int rtctime_dsleep_aligned (lua_State *L) } -static void add_table_item (lua_State *L, const char *key, int val) -{ - lua_pushstring (L, key); - lua_pushinteger (L, val); - lua_rawset (L, -3); -} +#define ADD_TABLE_ITEM(L, key, val) \ + lua_pushinteger (L, val); \ + lua_setfield (L, -2, key); // rtctime.epoch2cal (stamp) static int rtctime_epoch2cal (lua_State *L) @@ -198,14 +195,14 @@ static int rtctime_epoch2cal (lua_State *L) /* construct Lua table */ lua_createtable (L, 0, 8); - add_table_item (L, "yday", date.tm_yday + 1); - add_table_item (L, "wday", date.tm_wday + 1); - add_table_item (L, "year", date.tm_year + 1900); - add_table_item (L, "mon", date.tm_mon + 1); - add_table_item (L, "day", date.tm_mday); - add_table_item (L, "hour", date.tm_hour); - add_table_item (L, "min", date.tm_min); - add_table_item (L, "sec", date.tm_sec); + ADD_TABLE_ITEM (L, "yday", date.tm_yday + 1); + ADD_TABLE_ITEM (L, "wday", date.tm_wday + 1); + ADD_TABLE_ITEM (L, "year", date.tm_year + 1900); + ADD_TABLE_ITEM (L, "mon", date.tm_mon + 1); + ADD_TABLE_ITEM (L, "day", date.tm_mday); + ADD_TABLE_ITEM (L, "hour", date.tm_hour); + ADD_TABLE_ITEM (L, "min", date.tm_min); + ADD_TABLE_ITEM (L, "sec", date.tm_sec); return 1; }