Skip to content

Commit

Permalink
30982bec968fd34694b5be3ecbbc92de78d8eacb
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan authored and well-in-that-case committed Aug 15, 2024
1 parent 5302d13 commit 0d5c43a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,8 @@ static const char *get_prompt (lua_State *L, int firstline) {
static int incomplete (lua_State *L, int status) {
if (status == LUA_ERRSYNTAX) {
const char *msg = lua_tostring(L, -1);
if (strstr(msg, "near '<eof>'") != nullptr) {
lua_pop(L, 1);
if (strstr(msg, "near '<eof>'") != nullptr)
return 1;
}
}
return 0; /* else... */
}
Expand All @@ -519,9 +517,9 @@ static int pushline (lua_State *L, int firstline) {
size_t l;
const char *prmt = get_prompt(L, firstline);
int readstatus = lua_readline(L, b, prmt);
if (readstatus == 0)
return 0; /* no input (prompt will be popped by caller) */
lua_pop(L, 1); /* remove prompt */
if (readstatus == 0)
return 0; /* no input */
l = strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
b[--l] = '\0'; /* remove it */
Expand Down Expand Up @@ -563,8 +561,9 @@ static int multiline (lua_State *L) {
int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
if (!incomplete(L, status) || !pushline(L, 0)) {
lua_saveline(L, line); /* keep history */
return status; /* cannot or should not try to add continuation line */
return status; /* should not or cannot try to add continuation line */
}
lua_remove(L, -2); /* remove error message (from incomplete line) */
lua_pushliteral(L, "\n"); /* add newline... */
lua_insert(L, -2); /* ...between the two lines */
lua_concat(L, 3); /* join them */
Expand Down

0 comments on commit 0d5c43a

Please sign in to comment.