summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Cleynhens <stijncleynhens@gmail.com>2016-12-05 15:11:05 +0100
committerFelix Fietkau <nbd@nbd.name>2016-12-05 18:11:50 +0100
commitf9db1cb918da64101fdc72422551d95b054b1a38 (patch)
tree50f59741ae3695bec91a1bee77d6efb7804cada7
parent77a629375d7387a33a59509d9d751a8798134cab (diff)
downloadlibubox-f9db1cb918da64101fdc72422551d95b054b1a38.tar.gz
libubox: allow reading out the remaining time of a uloop timer in Lua
Add Lua method to the uloop wrapper to allow reading out the remaining time of a uloop timer Signed-off-by: Stijn Cleynhens <stijncleynhens@gmail.com>
-rw-r--r--lua/uloop.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lua/uloop.c b/lua/uloop.c
index c5dd12f..a78c2dc 100644
--- a/lua/uloop.c
+++ b/lua/uloop.c
@@ -94,6 +94,15 @@ static int ul_timer_set(lua_State *L)
return 1;
}
+static int ul_timer_remaining(lua_State *L)
+{
+ struct lua_uloop_timeout *tout;
+
+ tout = lua_touserdata(L, 1);
+ lua_pushnumber(L, uloop_timeout_remaining(&tout->t));
+ return 1;
+}
+
static int ul_timer_free(lua_State *L)
{
struct lua_uloop_timeout *tout = lua_touserdata(L, 1);
@@ -114,6 +123,7 @@ static int ul_timer_free(lua_State *L)
static const luaL_Reg timer_m[] = {
{ "set", ul_timer_set },
+ { "remaining", ul_timer_remaining },
{ "cancel", ul_timer_free },
{ NULL, NULL }
};