** Prompt the user, read a line, and push it into the Lua stack. */
| 503 | ** Prompt the user, read a line, and push it into the Lua stack. |
| 504 | */ |
| 505 | static int pushline (lua_State *L, int firstline) { |
| 506 | char buffer[LUA_MAXINPUT]; |
| 507 | char *b = buffer; |
| 508 | size_t l; |
| 509 | const char *prmt = get_prompt(L, firstline); |
| 510 | int readstatus = lua_readline(L, b, prmt); |
| 511 | if (readstatus == 0) |
| 512 | return 0; /* no input (prompt will be popped by caller) */ |
| 513 | lua_pop(L, 1); /* remove prompt */ |
| 514 | l = strlen(b); |
| 515 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ |
| 516 | b[--l] = '\0'; /* remove it */ |
| 517 | if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */ |
| 518 | lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ |
| 519 | else |
| 520 | lua_pushlstring(L, b, l); |
| 521 | lua_freeline(L, b); |
| 522 | return 1; |
| 523 | } |
| 524 | |
| 525 | |
| 526 | /* |
no test coverage detected