** Prompt the user, read a line, and push it into the Lua stack. */
| 452 | ** Prompt the user, read a line, and push it into the Lua stack. |
| 453 | */ |
| 454 | static int pushline (lua_State *L, int firstline) { |
| 455 | char buffer[LUA_MAXINPUT]; |
| 456 | char *b = buffer; |
| 457 | size_t l; |
| 458 | const char *prmt = get_prompt(L, firstline); |
| 459 | int readstatus = lua_readline(L, b, prmt); |
| 460 | if (readstatus == 0) |
| 461 | return 0; /* no input (prompt will be popped by caller) */ |
| 462 | lua_pop(L, 1); /* remove prompt */ |
| 463 | l = strlen(b); |
| 464 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ |
| 465 | b[--l] = '\0'; /* remove it */ |
| 466 | if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */ |
| 467 | lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ |
| 468 | else |
| 469 | lua_pushlstring(L, b, l); |
| 470 | lua_freeline(L, b); |
| 471 | return 1; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | /* |
no test coverage detected