Software / code / prosody
Comparison
util-src/time.c @ 9163:6b1f46730217
util.time: Add monotonic time
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 09 Mar 2017 04:37:12 +0100 |
| parent | 9162:8ad1fe9d26d4 |
| child | 9164:35807f02bdc7 |
comparison
equal
deleted
inserted
replaced
| 9162:8ad1fe9d26d4 | 9163:6b1f46730217 |
|---|---|
| 12 clock_gettime(CLOCK_REALTIME, &t); | 12 clock_gettime(CLOCK_REALTIME, &t); |
| 13 lua_pushnumber(L, tv2number(&t)); | 13 lua_pushnumber(L, tv2number(&t)); |
| 14 return 1; | 14 return 1; |
| 15 } | 15 } |
| 16 | 16 |
| 17 int lc_time_monotonic(lua_State *L) { | |
| 18 struct timespec t; | |
| 19 clock_gettime(CLOCK_MONOTONIC, &t); | |
| 20 lua_pushnumber(L, tv2number(&t)); | |
| 21 return 1; | |
| 22 } | |
| 23 | |
| 17 int luaopen_util_time(lua_State *L) { | 24 int luaopen_util_time(lua_State *L) { |
| 18 lua_createtable(L, 0, 2); | 25 lua_createtable(L, 0, 2); |
| 19 { | 26 { |
| 20 lua_pushcfunction(L, lc_time_realtime); | 27 lua_pushcfunction(L, lc_time_realtime); |
| 21 lua_setfield(L, -2, "now"); | 28 lua_setfield(L, -2, "now"); |
| 29 lua_pushcfunction(L, lc_time_monotonic); | |
| 30 lua_setfield(L, -2, "monotonic"); | |
| 22 } | 31 } |
| 23 return 1; | 32 return 1; |
| 24 } | 33 } |