[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: deadline replacement
- From: eugeny gladkih <john@...>
- Date: Tue, 26 Oct 2021 20:13:27 +0300
re,
and better version with Windows specifics
--- orig-5.4.3/lua.c 2021-10-26 15:31:11.000000000 +0300
+++ lua-5.4.3/src/lua.c 2021-10-26 20:11:45.000000000 +0300
@@ -421,6 +421,37 @@
#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() {
+#if defined( _WIN32 )
+ const char *home = getenv( "USERPROFILE" );
+#else
+ const char *home = getenv( "HOME" );
+#endif
+ 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
+ linenoiseInstallWindowChangeHandler();
+#endif
+}
#else /* }{ */
#define lua_initreadline(L) ((void)L)
> On 26 Oct 2021, at 15:41, eugeny gladkih <john@drweb.com> wrote:
>
> 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
--
Yours sincerely, Eugeny.
+33 6 38 52 27 93