Fix some issues and do some code cleanup

This commit is contained in:
Justine Tunney 2022-05-23 10:15:53 -07:00
parent 1f229e4efc
commit 312ed5c67c
72 changed files with 880 additions and 982 deletions

View file

@ -234,9 +234,9 @@ static ssize_t pushline (lua_State *L, int firstline) {
ssize_t rc;
char *prmt;
globalL = L;
prmt = strdup(get_prompt(L, firstline));
lua_pop(L, 1); /* remove prompt */
if (lua_repl_isterminal) {
prmt = strdup(get_prompt(L, firstline));
lua_pop(L, 1); /* remove prompt */
LUA_REPL_UNLOCK;
rc = linenoiseEdit(lua_repl_linenoise, prmt, &b, !firstline || lua_repl_blocking);
free(prmt);
@ -250,9 +250,17 @@ static ssize_t pushline (lua_State *L, int firstline) {
LUA_REPL_LOCK;
} else {
LUA_REPL_UNLOCK;
fputs(prmt, stdout);
fflush(stdout);
b = linenoiseGetLine(stdin);
if (b) {
rc = 1;
} else if (ferror(stdin)) {
rc = -1;
} else {
rc = 0;
}
LUA_REPL_LOCK;
rc = b ? 1 : -1;
}
if (!(rc == -1 && errno == EAGAIN)) {
write(1, "\n", 1);

View file

@ -307,7 +307,8 @@ static void doREPL (lua_State *L) {
progname = NULL; /* no 'progname' on errors in interactive mode */
lua_initrepl(L, LUA_PROGNAME);
for (;;) {
linenoiseEnableRawMode(0);
if (lua_repl_isterminal)
linenoiseEnableRawMode(0);
TryAgain:
status = lua_loadline(L);
if (status == -2 && errno == EAGAIN) {
@ -315,7 +316,8 @@ static void doREPL (lua_State *L) {
poll(&(struct pollfd){0, POLLIN}, 1, -1);
goto TryAgain;
}
linenoiseDisableRawMode();
if (lua_repl_isterminal)
linenoiseDisableRawMode();
if (status == -1) {
break;
} else if (status == -2) {