diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-06-06 11:39:55 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-06-06 11:50:06 +0100 |
commit | 659eb51e4c05c2a21ad0f9541762a0c4763d3d05 (patch) | |
tree | 9b9d7848e3deba953a1fb270a7f214125ae1dad4 | |
parent | cd229708f70ea141ff5eaa3d27638c61dac028e8 (diff) | |
download | rspamd-659eb51e4c05c2a21ad0f9541762a0c4763d3d05.tar.gz rspamd-659eb51e4c05c2a21ad0f9541762a0c4763d3d05.zip |
[Fix] As we have replxx library, always use it
-rw-r--r-- | cmake/AddDependencySubdirectories.cmake | 2 | ||||
-rw-r--r-- | config.h.in | 1 | ||||
-rw-r--r-- | src/lua/lua_util.c | 26 | ||||
-rw-r--r-- | src/rspamadm/lua_repl.c | 23 |
4 files changed, 5 insertions, 47 deletions
diff --git a/cmake/AddDependencySubdirectories.cmake b/cmake/AddDependencySubdirectories.cmake index 56932e9c6..2f8531888 100644 --- a/cmake/AddDependencySubdirectories.cmake +++ b/cmake/AddDependencySubdirectories.cmake @@ -76,7 +76,6 @@ function(AddDependencySubdirectories) # Lua REPL support add_subdirectory(contrib/replxx) - set(WITH_LUA_REPL 1 PARENT_SCOPE) list(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-replxx) # Update the required libraries list based on dependencies @@ -106,5 +105,4 @@ function(AddDependencySubdirectories) # Propagate variables to parent scope set(RSPAMD_REQUIRED_LIBRARIES ${RSPAMD_REQUIRED_LIBRARIES} PARENT_SCOPE) set(WITH_SNOWBALL ${WITH_SNOWBALL} PARENT_SCOPE) - set(WITH_LUA_REPL ${WITH_LUA_REPL} PARENT_SCOPE) endfunction() diff --git a/config.h.in b/config.h.in index 0ed2cd6b2..f9d910d68 100644 --- a/config.h.in +++ b/config.h.in @@ -112,7 +112,6 @@ #cmakedefine WITH_SNOWBALL 1 #cmakedefine WITH_SQLITE 1 #cmakedefine WITH_LUA_TRACE 1 -#cmakedefine WITH_LUA_REPL 1 #cmakedefine WITH_FASTTEXT 1 #cmakedefine BACKWARD_ENABLE 1 #cmakedefine HAVE_BUILTIN_CPU_SUPPORTS 1 diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 9fe862757..3503dbb21 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -23,10 +23,8 @@ #include "lua_parsers.h" -#ifdef WITH_LUA_REPL -#include "replxx.h" -#endif +#include "replxx.h" #include <math.h> #include <glob.h> @@ -2510,7 +2508,7 @@ lua_util_readline(lua_State *L) if (lua_type(L, 1) == LUA_TSTRING) { prompt = lua_tostring(L, 1); } -#ifdef WITH_LUA_REPL + static Replxx *rx_instance = NULL; if (rx_instance == NULL) { @@ -2527,26 +2525,6 @@ lua_util_readline(lua_State *L) else { lua_pushnil(L); } -#else - size_t linecap = 0; - ssize_t linelen; - - fprintf(stdout, "%s ", prompt); - - linelen = getline(&input, &linecap, stdin); - - if (linelen > 0) { - if (input[linelen - 1] == '\n') { - linelen--; - } - - lua_pushlstring(L, input, linelen); - free(input); - } - else { - lua_pushnil(L); - } -#endif return 1; } diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c index 9ad790d20..f9099d895 100644 --- a/src/rspamadm/lua_repl.c +++ b/src/rspamadm/lua_repl.c @@ -24,9 +24,8 @@ #include "lua/lua_thread_pool.h" #include "message.h" #include "unix-std.h" -#ifdef WITH_LUA_REPL + #include "replxx.h" -#endif #include "worker_util.h" #ifdef WITH_LUAJIT #include <luajit.h> @@ -43,10 +42,7 @@ static int batch = -1; extern struct rspamd_async_session *rspamadm_session; static const char *default_history_file = ".rspamd_repl.hist"; - -#ifdef WITH_LUA_REPL static Replxx *rx_instance = NULL; -#endif #ifdef WITH_LUAJIT #define MAIN_PROMPT LUAJIT_VERSION "> " @@ -272,7 +268,7 @@ rspamadm_exec_input(lua_State *L, const char *input) } else { lua_logger_out(L, i, outbuf, sizeof(outbuf), - LUA_ESCAPE_UNPRINTABLE); + LUA_ESCAPE_UNPRINTABLE); rspamd_printf("%s\n", outbuf); } } @@ -453,7 +449,7 @@ rspamadm_lua_message_handler(lua_State *L, int argc, char **argv) for (j = old_top + 1; j <= lua_gettop(L); j++) { lua_logger_out(L, j, outbuf, sizeof(outbuf), - LUA_ESCAPE_UNPRINTABLE); + LUA_ESCAPE_UNPRINTABLE); rspamd_printf("%s\n", outbuf); } } @@ -499,7 +495,6 @@ rspamadm_lua_try_dot_command(lua_State *L, const char *input) return FALSE; } -#ifdef WITH_LUA_REPL static int lex_ref_idx = -1; static void @@ -595,20 +590,14 @@ lua_syntax_highlighter(const char *str, ReplxxColor *colours, int size, void *ud lua_settop(L, 0); } -#endif static void rspamadm_lua_run_repl(lua_State *L, bool is_batch) { char *input = NULL; -#ifdef WITH_LUA_REPL gboolean is_multiline = FALSE; GString *tb = NULL; gsize i; -#else - /* Always set is_batch */ - is_batch = TRUE; -#endif for (;;) { if (is_batch) { @@ -640,7 +629,6 @@ rspamadm_lua_run_repl(lua_State *L, bool is_batch) lua_settop(L, 0); } else { -#ifdef WITH_LUA_REPL replxx_set_highlighter_callback(rx_instance, lua_syntax_highlighter, L); @@ -701,7 +689,6 @@ rspamadm_lua_run_repl(lua_State *L, bool is_batch) g_string_append(tb, " \n"); } } -#endif } } } @@ -1005,16 +992,12 @@ rspamadm_lua(int argc, char **argv, const struct rspamadm_command *cmd) } if (!batch) { -#ifdef WITH_LUA_REPL rx_instance = replxx_init(); replxx_set_max_history_size(rx_instance, max_history); replxx_history_load(rx_instance, histfile); -#endif rspamadm_lua_run_repl(L, false); -#ifdef WITH_LUA_REPL replxx_history_save(rx_instance, histfile); replxx_end(rx_instance); -#endif } else { rspamadm_lua_run_repl(L, true); |