| 58 | using namespace dfproto; |
| 59 | |
| 60 | int main (int argc, char *argv[]) |
| 61 | { |
| 62 | Console out; |
| 63 | |
| 64 | if (argc <= 1) |
| 65 | { |
| 66 | fprintf(stderr, "Usage: dfhack-run <command> [args...]\n\n"); |
| 67 | fprintf(stderr, "Note: this command does not start DFHack; it is intended to connect\n" |
| 68 | "to a running DFHack instance. If you were trying to start DFHack, run\n" |
| 69 | #ifdef _WIN32 |
| 70 | " Dwarf Fortress.exe\n" |
| 71 | #else |
| 72 | " ./dfhack\n" |
| 73 | #endif |
| 74 | "or see the documentation in hack/docs/index.html for more help.\n" |
| 75 | ); |
| 76 | #ifdef _WIN32 |
| 77 | fprintf(stderr, "\nPress Enter to quit.\n"); |
| 78 | fgetc(stdin); |
| 79 | #endif |
| 80 | return 2; |
| 81 | } |
| 82 | |
| 83 | // Connect to DFHack |
| 84 | RemoteClient client(&out); |
| 85 | if (!client.connect()) |
| 86 | return 2; |
| 87 | |
| 88 | out.init(true); |
| 89 | |
| 90 | command_result rv; |
| 91 | |
| 92 | if (strcmp(argv[1], "--lua") == 0) |
| 93 | { |
| 94 | if (argc <= 3) |
| 95 | { |
| 96 | out.shutdown(); |
| 97 | fprintf(stderr, "Usage: dfhack-run --lua <module> <function> [args...]\n"); |
| 98 | return 2; |
| 99 | } |
| 100 | |
| 101 | RemoteFunction<dfproto::CoreRunLuaRequest,dfproto::StringListMessage> run_call; |
| 102 | |
| 103 | if (!run_call.bind(&client, "RunLua")) |
| 104 | { |
| 105 | out.shutdown(); |
| 106 | fprintf(stderr, "No RunLua protocol function found."); |
| 107 | return 3; |
| 108 | } |
| 109 | |
| 110 | run_call.in()->set_module(argv[2]); |
| 111 | run_call.in()->set_function(argv[3]); |
| 112 | for (int i = 4; i < argc; i++) |
| 113 | run_call.in()->add_arguments(argv[i]); |
| 114 | |
| 115 | rv = run_call(); |
| 116 | |
| 117 | out.flush(); |
nothing calls this directly
no test coverage detected