Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
87e1abfb
Commit
87e1abfb
authored
Jan 22, 2017
by
Arnim Läuger
Committed by
Philip Gladstone
Jan 22, 2017
Browse files
rtctime: change to lua_setfieldfor populating the table (#1746)
Looks good.
parent
88938b44
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/rtctime.c
View file @
87e1abfb
...
@@ -180,12 +180,9 @@ static int rtctime_dsleep_aligned (lua_State *L)
...
@@ -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
)
#define ADD_TABLE_ITEM(L, key, val) \
{
lua_pushinteger (L, val); \
lua_pushstring
(
L
,
key
);
lua_setfield (L, -2, key);
lua_pushinteger
(
L
,
val
);
lua_rawset
(
L
,
-
3
);
}
// rtctime.epoch2cal (stamp)
// rtctime.epoch2cal (stamp)
static
int
rtctime_epoch2cal
(
lua_State
*
L
)
static
int
rtctime_epoch2cal
(
lua_State
*
L
)
...
@@ -198,14 +195,14 @@ static int rtctime_epoch2cal (lua_State *L)
...
@@ -198,14 +195,14 @@ static int rtctime_epoch2cal (lua_State *L)
/* construct Lua table */
/* construct Lua table */
lua_createtable
(
L
,
0
,
8
);
lua_createtable
(
L
,
0
,
8
);
add_table_item
(
L
,
"yday"
,
date
.
tm_yday
+
1
);
ADD_TABLE_ITEM
(
L
,
"yday"
,
date
.
tm_yday
+
1
);
add_table_item
(
L
,
"wday"
,
date
.
tm_wday
+
1
);
ADD_TABLE_ITEM
(
L
,
"wday"
,
date
.
tm_wday
+
1
);
add_table_item
(
L
,
"year"
,
date
.
tm_year
+
1900
);
ADD_TABLE_ITEM
(
L
,
"year"
,
date
.
tm_year
+
1900
);
add_table_item
(
L
,
"mon"
,
date
.
tm_mon
+
1
);
ADD_TABLE_ITEM
(
L
,
"mon"
,
date
.
tm_mon
+
1
);
add_table_item
(
L
,
"day"
,
date
.
tm_mday
);
ADD_TABLE_ITEM
(
L
,
"day"
,
date
.
tm_mday
);
add_table_item
(
L
,
"hour"
,
date
.
tm_hour
);
ADD_TABLE_ITEM
(
L
,
"hour"
,
date
.
tm_hour
);
add_table_item
(
L
,
"min"
,
date
.
tm_min
);
ADD_TABLE_ITEM
(
L
,
"min"
,
date
.
tm_min
);
add_table_item
(
L
,
"sec"
,
date
.
tm_sec
);
ADD_TABLE_ITEM
(
L
,
"sec"
,
date
.
tm_sec
);
return
1
;
return
1
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment