diff --git a/src/box/lua/console.c b/src/box/lua/console.c index a66b309f147db4db2c410574a21631fa3a073eac..d203629d123736ebf24ce526081d5c8263a4df9d 100644 --- a/src/box/lua/console.c +++ b/src/box/lua/console.c @@ -51,6 +51,8 @@ #include <stdlib.h> #include <ctype.h> +struct rlist on_console_eval = RLIST_HEAD_INITIALIZER(on_console_eval); + static struct luaL_serializer *serializer_yaml; static struct luaL_serializer *serializer_lua; @@ -472,6 +474,18 @@ lbox_console_format_yaml(struct lua_State *L) return lua_yaml_encode(L, serializer_yaml, NULL, NULL); } +/** + * Runs registered on_console_eval triggers. + * Takes eval expression string, which is passed to trigger callback. + */ +static int +lbox_console_run_on_eval(struct lua_State *L) +{ + const char *expr = lua_tostring(L, 1); + trigger_run(&on_console_eval, (void *)expr); + return 0; +} + int console_session_fd(struct session *session) { @@ -641,6 +655,7 @@ tarantool_lua_console_init(struct lua_State *L) {"completion_handler", lbox_console_completion_handler}, {"format_yaml", lbox_console_format_yaml}, {"format_lua", lbox_console_format_lua}, + {"run_on_eval", lbox_console_run_on_eval}, {NULL, NULL} }; luaL_register_module(L, "console", consolelib); diff --git a/src/box/lua/console.h b/src/box/lua/console.h index 208b314909eadf7ba682e97f26a1f48b0dda5e8a..29348f5af332d79460e1a4ea4fcfa9fa80170b76 100644 --- a/src/box/lua/console.h +++ b/src/box/lua/console.h @@ -30,10 +30,19 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +#include "small/rlist.h" + #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +/** + * Triggers invoked on console eval. + * Passed eval expression string. + */ +extern struct rlist on_console_eval; + struct lua_State; void diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 09c9d11f0aafde99edcdb443d5a14b1d96043442..69d9d992109d4c96187b189a49a33d3709408422 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -380,6 +380,7 @@ local function local_eval(storage, line) if not line then return nil end + internal.run_on_eval(line) local command = get_command(line) if command then return preprocess(storage, command)