aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-16 11:23:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-16 11:23:08 -0300
commitc3cb31fa9aae0c004c1c145b2268c0ffa35a3f62 (patch)
tree214d81dec7288f31128faba737c7d13c89c58ed0 /lua.c
parent0c7738240ef81b88ded842e3a8ebfb3180bcf00c (diff)
downloadlua-c3cb31fa9aae0c004c1c145b2268c0ffa35a3f62.tar.gz
lua-c3cb31fa9aae0c004c1c145b2268c0ffa35a3f62.tar.bz2
lua-c3cb31fa9aae0c004c1c145b2268c0ffa35a3f62.zip
some extra goodies for 'readline'
('rl_readline_name' and 'rl_inhibit_completion')
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lua.c b/lua.c
index 2e95c40b..ae783a0d 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.233 2018/02/06 15:32:36 roberto Exp roberto $ 2** $Id: lua.c,v 1.234 2018/03/06 20:30:17 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -383,12 +383,15 @@ static int handle_luainit (lua_State *L) {
383 383
384#include <readline/readline.h> 384#include <readline/readline.h>
385#include <readline/history.h> 385#include <readline/history.h>
386#define lua_initreadline(L) \
387 ((void)L, rl_readline_name="lua", rl_inhibit_completion=1)
386#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) 388#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
387#define lua_saveline(L,line) ((void)L, add_history(line)) 389#define lua_saveline(L,line) ((void)L, add_history(line))
388#define lua_freeline(L,b) ((void)L, free(b)) 390#define lua_freeline(L,b) ((void)L, free(b))
389 391
390#else /* }{ */ 392#else /* }{ */
391 393
394#define lua_initreadline(L) ((void)L)
392#define lua_readline(L,b,p) \ 395#define lua_readline(L,b,p) \
393 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ 396 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
394 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ 397 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
@@ -539,6 +542,7 @@ static void doREPL (lua_State *L) {
539 int status; 542 int status;
540 const char *oldprogname = progname; 543 const char *oldprogname = progname;
541 progname = NULL; /* no 'progname' on errors in interactive mode */ 544 progname = NULL; /* no 'progname' on errors in interactive mode */
545 lua_initreadline(L);
542 while ((status = loadline(L)) != -1) { 546 while ((status = loadline(L)) != -1) {
543 if (status == LUA_OK) 547 if (status == LUA_OK)
544 status = docall(L, 0, LUA_MULTRET); 548 status = docall(L, 0, LUA_MULTRET);