From 75591b77cec803d35447d7636f8719feedd219b7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 22 Apr 2017 14:33:05 +0100 Subject: [PATCH] [Minor] Add config:add_example function --- src/lua/lua_config.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 710604cf6..e59595447 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -577,6 +577,17 @@ LUA_FUNCTION_DEF (config, register_monitored); */ LUA_FUNCTION_DEF (config, add_doc); +/*** + * @method rspamd_config:add_example(path, option, doc_string, example) + * Adds new documentation + * + * @param {string} path documentation path (e.g. module name or nil for top) + * @param {string} option name of the option + * @param {string} doc_string documentation string + * @param {string} example example in ucl format, comments are also parsed + */ +LUA_FUNCTION_DEF (config, add_example); + /*** * @method rspamd_config:set_peak_cb(function) * Sets a function that will be called when frequency of some symbol goes out of @@ -639,6 +650,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, register_finish_script), LUA_INTERFACE_DEF (config, register_monitored), LUA_INTERFACE_DEF (config, add_doc), + LUA_INTERFACE_DEF (config, add_example), LUA_INTERFACE_DEF (config, set_peak_cb), {"__tostring", rspamd_lua_class_tostring}, {"__newindex", lua_config_newindex}, @@ -2631,6 +2643,31 @@ lua_config_add_doc (lua_State *L) return 0; } +static gint +lua_config_add_example (lua_State *L) +{ + struct rspamd_config *cfg; + const gchar *path, *option, *doc_string, *example; + gsize example_len; + + cfg = lua_check_config (L, 1); + path = luaL_checkstring (L, 2); + option = luaL_checkstring (L, 3); + doc_string = luaL_checkstring (L, 4); + example = luaL_checklstring (L, 5, &example_len); + + if (cfg && path && option && doc_string && example) { + + rspamd_rcl_add_doc_by_example (cfg, path, doc_string, option, + example, example_len); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 0; +} + static gint lua_monitored_alive (lua_State *L) { -- 2.39.5