** Prompt the user, read a line, and push it into the Lua stack. */
| 305 | ** Prompt the user, read a line, and push it into the Lua stack. |
| 306 | */ |
| 307 | static int pushline (lua_State *L, int firstline) { |
| 308 | char buffer[LUA_MAXINPUT]; |
| 309 | char *b = buffer; |
| 310 | size_t l; |
| 311 | const char *prmt = get_prompt(L, firstline); |
| 312 | int readstatus = lua_readline(L, b, prmt); |
| 313 | if (readstatus == 0) |
| 314 | return 0; /* no input (prompt will be popped by caller) */ |
| 315 | lua_pop(L, 1); /* remove prompt */ |
| 316 | l = strlen(b); |
| 317 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ |
| 318 | b[--l] = '\0'; /* remove it */ |
| 319 | if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */ |
| 320 | lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ |
| 321 | else |
| 322 | lua_pushlstring(L, b, l); |
| 323 | lua_freeline(L, b); |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | /* |
no test coverage detected