From 6f854176850ae787ad9bbd6743fa59b671e407a2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Mar 2015 11:56:10 +0000 Subject: [PATCH] Add lua-expr:process method. --- src/lua/lua_expression.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lua/lua_expression.c b/src/lua/lua_expression.c index 284fccb65..b4ca29602 100644 --- a/src/lua/lua_expression.c +++ b/src/lua/lua_expression.c @@ -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) { -- 2.39.5