]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to extract functions from lua tables
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Mar 2016 17:55:07 +0000 (17:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Mar 2016 17:55:07 +0000 (17:55 +0000)
src/lua/lua_common.c
src/lua/lua_common.h

index d2e64ad6ab6d4b6b0b77ae3ad5a9e7ab1e32fb10..992184ee234cfeba0df527b17fc46f4e97f08ff4 100644 (file)
@@ -689,6 +689,34 @@ rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
                                lua_pop (L, 1);
                                break;
 
+                       case 'F':
+                               if (lua_type (L, -1) == LUA_TFUNCTION) {
+                                       *(va_arg (ap, gint *)) = luaL_ref (L, LUA_REGISTRYINDEX);
+                               }
+                               else if (lua_type (L, -1) == LUA_TNIL) {
+                                       failed = TRUE;
+                                       *(va_arg (ap,  gint *)) = -1;
+                                       lua_pop (L, 1);
+                               }
+                               else {
+                                       g_set_error (err,
+                                                       lua_error_quark (),
+                                                       1,
+                                                       "bad type for key:"
+                                                                       " %.*s: '%s', '%s' is expected",
+                                                       (gint) keylen,
+                                                       key,
+                                                       lua_typename (L, lua_type (L, -1)),
+                                                       "function");
+                                       va_end (ap);
+                                       lua_pop (L, 1);
+
+                                       return FALSE;
+                               }
+
+                               /* luaL_ref pops argument from the stack */
+                               break;
+
                        case 'B':
                                if (lua_type (L, -1) == LUA_TBOOLEAN) {
                                        *(va_arg (ap, gboolean *)) = lua_toboolean (L, -1);
index 5356c3821d68305b5d55dc614703c920c8fad45a..39f578ea693975119d2acd234f00ed9a9280ad2b 100644 (file)
@@ -307,6 +307,7 @@ struct rspamd_config * lua_check_config (lua_State * L, gint pos);
  * - B - boolean
  * - V - size_t + const char *
  * - U{classname} - userdata of the following class (stored in gpointer)
+ * - F - function
  *
  * If any of format string is prefixed with `*` then it is treated as required argument
  * @param L lua state