From 15a8f03f67f78fe6fd418845b0ef8ab1fd9d352c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 13 Jan 2016 01:15:51 +0100 Subject: [PATCH] Uptime function --- src/c/lnative.c | 9 +++++++++ src/lua/core/computer.lua | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/c/lnative.c b/src/c/lnative.c index 61430d2..b9c32bf 100644 --- a/src/c/lnative.c +++ b/src/c/lnative.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,13 @@ static int l_beep (lua_State *L) { return 0; } +static int l_uptime (lua_State *L) { //Return ms + struct timeval tp; + gettimeofday(&tp, NULL); + lua_pushnumber(L, tp.tv_sec * 1000 + tp.tv_usec / 1000); + return 1; +} + void luanative_start(lua_State *L) { lua_createtable (L, 0, 1); @@ -333,6 +341,7 @@ void luanative_start(lua_State *L) { pushctuple(L, "fs_read", l_fs_read); pushctuple(L, "beep", l_beep); + pushctuple(L, "uptime", l_uptime); lua_setglobal(L, "native"); } \ No newline at end of file diff --git a/src/lua/core/computer.lua b/src/lua/core/computer.lua index 3287952..c26d69e 100644 --- a/src/lua/core/computer.lua +++ b/src/lua/core/computer.lua @@ -18,7 +18,7 @@ function api.pullSignal(timeout) end function api.uptime() - return native.uptime() + return native.uptime() / 1000 end function api.beep(freq, time)