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

Method invoke

library/PluginManager.cpp:489–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487}
488
489command_result Plugin::invoke(color_ostream &out, const std::string & command, std::vector <std::string> & parameters)
490{
491 command_result cr = CR_NOT_IMPLEMENTED;
492 access->lock_add();
493 if (state == PS_LOADED) {
494 if (auto cmdIt = std::ranges::find_if(commands, [&](const PluginCommand &cmd) { return cmd.name == command; });
495 commands.end() != cmdIt)
496 {
497 // running interactive things from some other source than the console would break it
498 if (!out.is_console() && cmdIt->interactive)
499 cr = CR_NEEDS_CONSOLE;
500 else if (cmdIt->guard) {
501 CoreSuspender suspend;
502 if (!cmdIt->guard(Core::getInstance().getTopViewscreen())) {
503 out.printerr("Could not invoke {}: unsuitable UI state.\n", command);
504 cr = CR_WRONG_USAGE;
505 }
506 else {
507 cr = cmdIt->function(out, parameters);
508 }
509 }
510 else if (cmdIt->unlocked) {
511 cr = cmdIt->function(out, parameters);
512 }
513 else {
514 CoreSuspender suspend;
515 cr = cmdIt->function(out, parameters);
516 }
517 }
518 }
519 access->lock_sub();
520 return cr;
521}
522
523bool Plugin::can_invoke_hotkey(const std::string & command, df::viewscreen *top )
524{

Callers 1

InvokeCommandMethod · 0.45

Calls 4

lock_addMethod · 0.80
getTopViewscreenMethod · 0.80
lock_subMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected