** Prompt the user, read a line, and push it into the Lua stack. */
| 477 | ** Prompt the user, read a line, and push it into the Lua stack. |
| 478 | */ |
| 479 | static int pushline (lua_State *L, int firstline) { |
| 480 | char buffer[LUA_MAXINPUT]; |
| 481 | char *b = buffer; |
| 482 | size_t l; |
| 483 | const char *prmt = get_prompt(L, firstline); |
| 484 | int readstatus = lua_readline(L, b, prmt); |
| 485 | if (readstatus == 0) |
| 486 | return 0; /* no input (prompt will be popped by caller) */ |
| 487 | lua_pop(L, 1); /* remove prompt */ |
| 488 | l = strlen(b); |
| 489 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ |
| 490 | b[--l] = '\0'; /* remove it */ |
| 491 | if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */ |
| 492 | lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ |
| 493 | else |
| 494 | lua_pushlstring(L, b, l); |
| 495 | lua_freeline(L, b); |
| 496 | return 1; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | /* |
no test coverage detected