| 420 | } |
| 421 | |
| 422 | static int dfhack_lineedit_sync(lua_State *S, Console *pstream) |
| 423 | { |
| 424 | const char *prompt = luaL_optstring(S, 1, ">> "); |
| 425 | const char *hfile = luaL_optstring(S, 2, NULL); |
| 426 | |
| 427 | DFHack::CommandHistory hist; |
| 428 | if (hfile) |
| 429 | hist.load(std::filesystem::path{ hfile }); |
| 430 | |
| 431 | std::string ret; |
| 432 | int rv = pstream->lineedit(prompt, ret, hist); |
| 433 | |
| 434 | if (rv == Console::RETRY) |
| 435 | rv = 0; /* return empty string to lua */ |
| 436 | |
| 437 | if (rv < 0) |
| 438 | { |
| 439 | lua_pushnil(S); |
| 440 | if (rv == Console::SHUTDOWN) |
| 441 | lua_pushstring(S, "shutdown requested"); |
| 442 | else |
| 443 | lua_pushstring(S, "input error"); |
| 444 | return 2; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | if (hfile) |
| 449 | hist.save(std::filesystem::path{ hfile }); |
| 450 | lua_pushlstring(S, ret.data(), ret.size()); |
| 451 | return 1; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | static int DFHACK_QUERY_COROTABLE_TOKEN = 0; |
| 456 |
no test coverage detected