** Prompt the user, read a line, and push it into the Lua stack. */
| 348 | ** Prompt the user, read a line, and push it into the Lua stack. |
| 349 | */ |
| 350 | static int pushline(lua_State *L, int firstline) { |
| 351 | char buffer[LUA_MAXINPUT]; |
| 352 | char *b = buffer; |
| 353 | size_t l; |
| 354 | const char *prmt = get_prompt(L, firstline); |
| 355 | int readstatus = lua_readline(L, b, prmt); |
| 356 | if (readstatus == 0 || lua_gettop(L) < 1) |
| 357 | return 0; /* no input (prompt will be popped by caller) */ |
| 358 | lua_pop(L, 1); /* remove prompt */ |
| 359 | l = strlen(b); |
| 360 | if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */ |
| 361 | b[--l] = '\0'; /* remove it */ |
| 362 | if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */ |
| 363 | lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ |
| 364 | else |
| 365 | lua_pushlstring(L, b, l); |
| 366 | lua_freeline(L, b); |
| 367 | return 1; |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /* |
no test coverage detected