Browse Source

[Feature] Allow to extract functions from lua tables

tags/1.2.0
Vsevolod Stakhov 8 years ago
parent
commit
095e129405
2 changed files with 29 additions and 0 deletions
  1. 28
    0
      src/lua/lua_common.c
  2. 1
    0
      src/lua/lua_common.h

+ 28
- 0
src/lua/lua_common.c View 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);

+ 1
- 0
src/lua/lua_common.h View 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

Loading…
Cancel
Save