1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

some extra goodies for 'readline'

('rl_readline_name' and 'rl_inhibit_completion')
This commit is contained in:
Roberto Ierusalimschy 2018-03-16 11:23:08 -03:00
parent 0c7738240e
commit c3cb31fa9a

6
lua.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.233 2018/02/06 15:32:36 roberto Exp roberto $
** $Id: lua.c,v 1.234 2018/03/06 20:30:17 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -383,12 +383,15 @@ static int handle_luainit (lua_State *L) {
#include <readline/readline.h>
#include <readline/history.h>
#define lua_initreadline(L) \
((void)L, rl_readline_name="lua", rl_inhibit_completion=1)
#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
#define lua_saveline(L,line) ((void)L, add_history(line))
#define lua_freeline(L,b) ((void)L, free(b))
#else /* }{ */
#define lua_initreadline(L) ((void)L)
#define lua_readline(L,b,p) \
((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
@ -539,6 +542,7 @@ static void doREPL (lua_State *L) {
int status;
const char *oldprogname = progname;
progname = NULL; /* no 'progname' on errors in interactive mode */
lua_initreadline(L);
while ((status = loadline(L)) != -1) {
if (status == LUA_OK)
status = docall(L, 0, LUA_MULTRET);