lua-users home
lua-l archive

deadline replacement

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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

AltStyle によって変換されたページ (->オリジナル) /