mirror of https://github.com/rusefi/lua.git
pops the string from 'get_prompt' only after using it
This commit is contained in:
parent
7a3de1aba3
commit
ab7086e209
7
lua.c
7
lua.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.c,v 1.204 2012/04/20 17:05:17 roberto Exp roberto $
|
** $Id: lua.c,v 1.205 2012/05/23 15:37:09 roberto Exp roberto $
|
||||||
** Lua stand-alone interpreter
|
** Lua stand-alone interpreter
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -237,7 +237,6 @@ static const char *get_prompt (lua_State *L, int firstline) {
|
||||||
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
|
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
|
||||||
p = lua_tostring(L, -1);
|
p = lua_tostring(L, -1);
|
||||||
if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
|
if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
|
||||||
lua_pop(L, 1); /* remove global */
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +262,9 @@ static int pushline (lua_State *L, int firstline) {
|
||||||
char *b = buffer;
|
char *b = buffer;
|
||||||
size_t l;
|
size_t l;
|
||||||
const char *prmt = get_prompt(L, firstline);
|
const char *prmt = get_prompt(L, firstline);
|
||||||
if (lua_readline(L, b, prmt) == 0)
|
int readstatus = lua_readline(L, b, prmt);
|
||||||
|
lua_pop(L, 1); /* remove result from 'get_prompt' */
|
||||||
|
if (readstatus == 0)
|
||||||
return 0; /* no input */
|
return 0; /* no input */
|
||||||
l = strlen(b);
|
l = strlen(b);
|
||||||
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
||||||
|
|
Loading…
Reference in New Issue