From a4b61b0dce1a82e4def7128e4b2f81f1c0803a02 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 5 Apr 2016 09:16:14 +0100 Subject: [PATCH] [Feature] Add util.get_ticks function --- src/lua/lua_util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 0707f098c..52e008571 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -223,6 +223,13 @@ LUA_FUNCTION_DEF (util, strcasecmp_ascii); */ LUA_FUNCTION_DEF (util, strequal_caseless); +/*** + * @function util.get_ticks() + * Returns current number of ticks as floating point number + * @return {number} number of current clock ticks (monotonically increasing) + */ +LUA_FUNCTION_DEF (util, get_ticks); + static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, create_event_base), LUA_INTERFACE_DEF (util, load_rspamd_config), @@ -247,6 +254,7 @@ static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, strcasecmp_utf8), LUA_INTERFACE_DEF (util, strcasecmp_ascii), LUA_INTERFACE_DEF (util, strequal_caseless), + LUA_INTERFACE_DEF (util, get_ticks), {NULL, NULL} }; @@ -1055,6 +1063,17 @@ lua_util_strequal_caseless (lua_State *L) return 1; } +static gint +lua_util_get_ticks (lua_State *L) +{ + gdouble ticks; + + ticks = rspamd_get_ticks (); + lua_pushnumber (L, ticks); + + return 1; +} + static gint lua_load_util (lua_State * L) { -- 2.39.5