diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-09-29 17:07:06 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-09-29 17:07:06 -0300 |
| commit | ab7086e209d49b6ff2593a7c97ddaed664a3960b (patch) | |
| tree | 87c672bab8c3b0dfe8ce04610581f22beb31bec2 | |
| parent | 7a3de1aba3817eada6045f45d3e62cb5fe638b4d (diff) | |
| download | lua-ab7086e209d49b6ff2593a7c97ddaed664a3960b.tar.gz lua-ab7086e209d49b6ff2593a7c97ddaed664a3960b.tar.bz2 lua-ab7086e209d49b6ff2593a7c97ddaed664a3960b.zip | |
pops the string from 'get_prompt' only after using it
| -rw-r--r-- | lua.c | 7 |
1 files changed, 4 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.204 2012/04/20 17:05:17 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.205 2012/05/23 15:37:09 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 | */ |
| @@ -237,7 +237,6 @@ static const char *get_prompt (lua_State *L, int firstline) { | |||
| 237 | lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); | 237 | lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); |
| 238 | p = lua_tostring(L, -1); | 238 | p = lua_tostring(L, -1); |
| 239 | if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); | 239 | if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); |
| 240 | lua_pop(L, 1); /* remove global */ | ||
| 241 | return p; | 240 | return p; |
| 242 | } | 241 | } |
| 243 | 242 | ||
| @@ -263,7 +262,9 @@ static int pushline (lua_State *L, int firstline) { | |||
| 263 | char *b = buffer; | 262 | char *b = buffer; |
| 264 | size_t l; | 263 | size_t l; |
| 265 | const char *prmt = get_prompt(L, firstline); | 264 | const char *prmt = get_prompt(L, firstline); |
| 266 | if (lua_readline(L, b, prmt) == 0) | 265 | int readstatus = lua_readline(L, b, prmt); |
| 266 | lua_pop(L, 1); /* remove result from 'get_prompt' */ | ||
| 267 | if (readstatus == 0) | ||
| 267 | return 0; /* no input */ | 268 | return 0; /* no input */ |
| 268 | l = strlen(b); | 269 | l = strlen(b); |
| 269 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ | 270 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ |
