diff options
Diffstat (limited to 'lem/utils.c')
-rw-r--r-- | lem/utils.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lem/utils.c b/lem/utils.c index d93cf98..ad93c6b 100644 --- a/lem/utils.c +++ b/lem/utils.c @@ -16,6 +16,7 @@ * along with LEM. If not, see <http://www.gnu.org/licenses/>. */ +#include <sys/time.h> #include <lem.h> static int @@ -191,6 +192,22 @@ resume(lua_State *T) return 0; } +static int +now_lua(lua_State *L) +{ + struct timeval tp; + lua_Number ret; + + (void)gettimeofday(&tp, NULL); + + ret = (lua_Number)tp.tv_usec; + ret /= 1.0e6; + ret += (lua_Number)tp.tv_sec; + + lua_pushnumber(L, ret); + return 1; +} + int luaopen_lem_utils(lua_State *L) { @@ -239,5 +256,9 @@ luaopen_lem_utils(lua_State *L) lua_pushcfunction(L, resume); lua_setfield(L, -2, "resume"); + /* set now function */ + lua_pushcfunction(L, now_lua); + lua_setfield(L, -2, "now"); + return 1; } |