Browse Source

[Minor] Add missing helper methods

tags/1.7.4
Vsevolod Stakhov 6 years ago
parent
commit
8a2e6e8817
1 changed files with 48 additions and 0 deletions
  1. 48
    0
      src/lua/lua_map.c

+ 48
- 0
src/lua/lua_map.c View File

@@ -94,6 +94,20 @@ LUA_FUNCTION_DEF (map, get_uri);
*/
LUA_FUNCTION_DEF (map, get_stats);

/***
* @method map:get_data_digest()
* Get data digest for specific map
* @return {string} 64 bit number represented as string (due to Lua limitations)
*/
LUA_FUNCTION_DEF (map, get_data_digest);

/***
* @method map:get_nelts()
* Get number of elements for specific map
* @return {number} number of elements in the map
*/
LUA_FUNCTION_DEF (map, get_nelts);

static const struct luaL_reg maplib_m[] = {
LUA_INTERFACE_DEF (map, get_key),
LUA_INTERFACE_DEF (map, is_signed),
@@ -103,6 +117,8 @@ static const struct luaL_reg maplib_m[] = {
LUA_INTERFACE_DEF (map, set_callback),
LUA_INTERFACE_DEF (map, get_uri),
LUA_INTERFACE_DEF (map, get_stats),
LUA_INTERFACE_DEF (map, get_data_digest),
LUA_INTERFACE_DEF (map, get_nelts),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
};
@@ -868,6 +884,38 @@ lua_map_get_stats (lua_State * L)
return 1;
}

static gint
lua_map_get_data_digest (lua_State * L)
{
struct rspamd_lua_map *map = lua_check_map (L, 1);
gchar numbuf[64];

if (map != NULL) {
rspamd_snprintf (numbuf, sizeof (numbuf), "%uL", map->map->digest);
lua_pushstring (L, numbuf);
}
else {
return luaL_error (L, "invalid arguments");
}

return 1;
}

static gint
lua_map_get_nelts (lua_State * L)
{
struct rspamd_lua_map *map = lua_check_map (L, 1);

if (map != NULL) {
lua_pushnumber (L, map->map->nelts);
}
else {
return luaL_error (L, "invalid arguments");
}

return 1;
}

static int
lua_map_is_signed (lua_State *L)
{

Loading…
Cancel
Save