From 336972d7e512db2c78d6facdd35e3a27e7f319fe Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 23 Aug 2014 10:35:20 -0700 Subject: [PATCH] Allow adding maps without description from lua. --- src/lua/lua_config.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 5dfbe90d6c..777ed33fdd 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1021,16 +1021,25 @@ lua_config_add_map (lua_State *L) struct rspamd_config *cfg = lua_check_config (L); const gchar *map_line, *description; struct lua_map_callback_data *cbdata, **pcbdata; + int cbidx; if (cfg) { map_line = luaL_checkstring (L, 2); - description = lua_tostring (L, 3); - if (lua_type (L, 4) == LUA_TFUNCTION) { + if (lua_gettop (L) == 4) { + description = lua_tostring (L, 3); + cbidx = 4; + } + else { + description = NULL; + cbidx = 3; + } + + if (lua_type (L, cbidx) == LUA_TFUNCTION) { cbdata = g_slice_alloc (sizeof (*cbdata)); cbdata->L = L; cbdata->data = NULL; - lua_pushvalue (L, 4); + lua_pushvalue (L, cbidx); /* Get a reference */ cbdata->ref = luaL_ref (L, LUA_REGISTRYINDEX); pcbdata = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (cbdata)); -- 2.47.3