]> source.dussan.org Git - rspamd.git/commitdiff
Add lua-expr:process method.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 11:56:10 +0000 (11:56 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 13:47:54 +0000 (13:47 +0000)
src/lua/lua_expression.c

index 284fccb650a923ab90e3be2df7226192a249a73c..b4ca29602e2545b2bcfd78215ad89948dbb8e41c 100644 (file)
@@ -62,8 +62,17 @@ LUA_FUNCTION_DEF (expr, create);
  */
 LUA_FUNCTION_DEF (expr, to_string);
 
+/***
+ * @method rspamd_expression:process(input)
+ * Executes the expression and pass input to process atom callbacks
+ * @param {any} input input data for processing callbacks
+ * @return {number} result of the expression evaluation
+ */
+LUA_FUNCTION_DEF (expr, process);
+
 static const struct luaL_reg exprlib_m[] = {
        LUA_INTERFACE_DEF (expr, to_string),
+       LUA_INTERFACE_DEF (expr, process),
        {"__tostring", lua_expr_to_string},
        {NULL, NULL}
 };
@@ -159,6 +168,19 @@ lua_atom_process (gpointer input, rspamd_expression_atom_t *atom)
        return ret;
 }
 
+static gint
+lua_expr_process (lua_State *L)
+{
+       struct lua_expression *e = rspamd_lua_expression (L, 1);
+       gint res;
+
+       res = rspamd_process_expression (e->expr, GINT_TO_POINTER (2));
+
+       lua_pushnumber (L, res);
+
+       return 1;
+}
+
 static gint
 lua_expr_create (lua_State *L)
 {