]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add util.get_ticks function
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Apr 2016 08:16:14 +0000 (09:16 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Apr 2016 09:06:35 +0000 (10:06 +0100)
src/lua/lua_util.c

index 0707f098ccf58d5bb3dc2fa1bc8489013981c386..52e0085719d97a91258c0bec0cf8b79ff466a791 100644 (file)
@@ -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)
 {