[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: deadline replacement
- From: eugeny gladkih <john@...>
- Date: Tue, 26 Oct 2021 15:41:10 +0300
re,
you know, redline is viral GNU monster, many people want to avoid usage of it.
so, I introduce Lua 5.4 linenoise usage patch. please include it in the future. no cent it costs.
--- orig-5.4.3/lua.c 2021-10-26 15:31:11.000000000 +0300
+++ lua-5.4.3/src/lua.c 2021-10-26 15:26:44.000000000 +0300
@@ -421,6 +421,33 @@
#define lua_saveline(L,line) ((void)L, add_history(line))
#define lua_freeline(L,b) ((void)L, free(b))
+#elif defined(LUA_USE_LINENOISE) /* }{ */
+
+#include <linenoise.h>
+#define lua_initreadline(L) ((void)L, linenoise_init())
+#define lua_readline(L,b,p) ((void)L, ((b)=linenoise(p)) != NULL)
+#define lua_saveline(L,line) ((void)L, linenoiseHistoryAdd(line), linenoiseHistorySave(linenoise_history) )
+#define lua_freeline(L,b) ((void)L, free(b))
+
+static char *linenoise_history = NULL;
+
+static void linenoise_init() {
+ const char *home = getenv( "HOME" );
+ static const char fn[] = "/.lua_history";
+
+ if( !home )
+ home = strdup( "." );
+
+ linenoise_history = (char*)malloc( strlen( home) + sizeof(fn) );
+ strcpy( linenoise_history, home );
+ strncat( linenoise_history, fn, sizeof(fn)-1 );
+
+ linenoiseSetMultiLine(1);
+ linenoiseHistoryLoad( linenoise_history );
+#if defined( _WIN32 ) && LUA_USE_LINENOISE > 0 /* linenoise-ng */
+ linenoiseInstallWindowChangeHandler();
+#endif
+}
#else /* }{ */
#define lua_initreadline(L) ((void)L)
--
Yours sincerely, Eugeny.
+33 6 38 52 27 93