diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-16 17:55:07 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-03-16 17:55:07 +0000 |
commit | 095e129405958c6d1313b479d6ecd9d6c7b4a76d (patch) | |
tree | ef764afbce16c0066a11c440908b8ca8b8ca25ce | |
parent | 0dca31d70718c5bbefc5013052f94115084fc548 (diff) | |
download | rspamd-095e129405958c6d1313b479d6ecd9d6c7b4a76d.tar.gz rspamd-095e129405958c6d1313b479d6ecd9d6c7b4a76d.zip |
[Feature] Allow to extract functions from lua tables
-rw-r--r-- | src/lua/lua_common.c | 28 | ||||
-rw-r--r-- | src/lua/lua_common.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index d2e64ad6a..992184ee2 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -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); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 5356c3821..39f578ea6 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -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 |