MCPcopy Create free account
hub / github.com/DFHack/dfhack / dfhack_lineedit_sync

Function dfhack_lineedit_sync

library/LuaTools.cpp:422–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422static 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
455static int DFHACK_QUERY_COROTABLE_TOKEN = 0;
456

Callers 2

dfhack_lineedit_contFunction · 0.85
dfhack_lineeditFunction · 0.85

Calls 8

lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushlstringFunction · 0.85
loadMethod · 0.45
lineeditMethod · 0.45
saveMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected