From 2e05df7ac52b6bbf63ba9fa2206fdb2e3a5dd577 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 14 Oct 2021 16:41:24 -0400 Subject: [PATCH] Pass argc and argv through to DrivenEngine::event_init --- luprex/core/cpp/drivenengine.cpp | 4 ++-- luprex/core/cpp/drivenengine.hpp | 4 ++-- luprex/core/cpp/driver-mingw.cpp | 8 ++++---- luprex/core/cpp/driver.hpp | 2 +- luprex/core/cpp/drivertests.cpp | 8 ++++---- luprex/core/cpp/lpxclient.cpp | 2 +- luprex/core/cpp/lpxserver.cpp | 2 +- luprex/core/cpp/main.cpp | 6 ++++-- luprex/core/cpp/textgame.cpp | 4 ++-- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/luprex/core/cpp/drivenengine.cpp b/luprex/core/cpp/drivenengine.cpp index f9d4a95e..9498cda1 100644 --- a/luprex/core/cpp/drivenengine.cpp +++ b/luprex/core/cpp/drivenengine.cpp @@ -207,8 +207,8 @@ void DrivenEngine::drv_set_lua_source(util::LuaSourcePtr source) { rescan_lua_source_ = false; } -void DrivenEngine::drv_invoke_event_init() { - event_init(); +void DrivenEngine::drv_invoke_event_init(int argc, char *argv[]) { + event_init(argc, argv); } void DrivenEngine::drv_invoke_event_update() { diff --git a/luprex/core/cpp/drivenengine.hpp b/luprex/core/cpp/drivenengine.hpp index 15580d60..63a06d23 100644 --- a/luprex/core/cpp/drivenengine.hpp +++ b/luprex/core/cpp/drivenengine.hpp @@ -191,7 +191,7 @@ public: // The update callback. You may override this in a subclass. // This will be called whenever anything changes. // - virtual void event_init() {} + virtual void event_init(int argc, char *argv[]) {} virtual void event_update() {} // Specify the set of listening ports. @@ -343,7 +343,7 @@ public: // Invoke the init or update event. // - void drv_invoke_event_init(); + void drv_invoke_event_init(int argc, char *argv[]); void drv_invoke_event_update(); // Check the 'rescan_lua_source' flag. If this flag is set, it means diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index 8b1e44ce..3a4ee4ca 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -325,7 +325,7 @@ public: } } - void drive(DrivenEngine *de) { + void drive(DrivenEngine *de, int argc, char *argv[]) { WSADATA whocares; assert(WSAStartup(MAKEWORD(2,2), &whocares) == 0); HANDLE hconsole = GetStdHandle(STD_INPUT_HANDLE); @@ -334,7 +334,7 @@ public: DrivenEngine::set(de); basetime_ = get_now(); driven_->drv_set_lua_source(util::read_lua_source("lua")); - driven_->drv_invoke_event_init(); + driven_->drv_invoke_event_init(argc, argv); handle_listen_ports(); while (!de->drv_get_stop_driver()) { short_sleep_ = false; @@ -353,8 +353,8 @@ public: }; -void driver_drive(DrivenEngine *de) { +void driver_drive(DrivenEngine *de, int argc, char *argv[]) { Driver driver; - driver.drive(de); + driver.drive(de, argc, argv); } diff --git a/luprex/core/cpp/driver.hpp b/luprex/core/cpp/driver.hpp index ed24bf48..4cc7bda7 100644 --- a/luprex/core/cpp/driver.hpp +++ b/luprex/core/cpp/driver.hpp @@ -3,6 +3,6 @@ #include "drivenengine.hpp" -void driver_drive(DrivenEngine *de); +void driver_drive(DrivenEngine *de, int argc, char *argv[]); #endif // DRIVER_HPP diff --git a/luprex/core/cpp/drivertests.cpp b/luprex/core/cpp/drivertests.cpp index 86433a0d..df51bc30 100644 --- a/luprex/core/cpp/drivertests.cpp +++ b/luprex/core/cpp/drivertests.cpp @@ -24,7 +24,7 @@ static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) { class DriverListenTest : public DrivenEngine { public: std::vector channels_; - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { listen_port(8085); } @@ -56,7 +56,7 @@ public: class DriverWebServerTest : public DrivenEngine { public: std::vector channels_; - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { UniqueChannel ch = new_outgoing_channel("stanford.edu:80"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); channels_.emplace_back(std::move(ch)); @@ -82,7 +82,7 @@ public: class DriverDNSFailTest : public DrivenEngine { public: std::vector channels_; - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { UniqueChannel ch = new_outgoing_channel("akjsdkajshdakjshd.alk:80"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); channels_.emplace_back(std::move(ch)); @@ -108,7 +108,7 @@ public: class DriverPrintClockTest : public DrivenEngine { public: int count; - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { count = 0; } diff --git a/luprex/core/cpp/lpxclient.cpp b/luprex/core/cpp/lpxclient.cpp index 2271ecbf..ae3c2c88 100644 --- a/luprex/core/cpp/lpxclient.cpp +++ b/luprex/core/cpp/lpxclient.cpp @@ -25,7 +25,7 @@ public: void do_command(const StringVec &exp); public: - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { } virtual void event_update() { diff --git a/luprex/core/cpp/lpxserver.cpp b/luprex/core/cpp/lpxserver.cpp index 8b0fb37b..b662d348 100644 --- a/luprex/core/cpp/lpxserver.cpp +++ b/luprex/core/cpp/lpxserver.cpp @@ -17,7 +17,7 @@ public: std::vector> clients_; public: - virtual void event_init() { + virtual void event_init(int argc, char *argv[]) { } virtual void event_update() { diff --git a/luprex/core/cpp/main.cpp b/luprex/core/cpp/main.cpp index 38c4af6a..d71a60af 100644 --- a/luprex/core/cpp/main.cpp +++ b/luprex/core/cpp/main.cpp @@ -33,7 +33,7 @@ static void usage() { int main(int argc, char **argv) { UniqueDrivenEngine engine; - if (argc != 2) usage(); + if (argc < 2) usage(); std::string mode = argv[1]; for (int i = 0; makers[i].name != nullptr; i++) { if (mode == makers[i].name) { @@ -42,6 +42,8 @@ int main(int argc, char **argv) } } if (engine == nullptr) usage(); - driver_drive(engine.get()); + // Remove one argument from the argument vector, + // so that it looks like a normal argument vector. + driver_drive(engine.get(), argc - 1, argv + 1); } diff --git a/luprex/core/cpp/textgame.cpp b/luprex/core/cpp/textgame.cpp index f9df95ff..ab91823b 100644 --- a/luprex/core/cpp/textgame.cpp +++ b/luprex/core/cpp/textgame.cpp @@ -41,7 +41,7 @@ private: void check_redirects(); public: - virtual void event_init(); + virtual void event_init(int argc, char *argv[]); virtual void event_update(); }; @@ -214,7 +214,7 @@ void TextGame::check_redirects() { } } -void TextGame::event_init() +void TextGame::event_init(int argc, char *argv[]) { world_.reset(new World(util::WORLD_TYPE_STANDALONE)); world_->update_source(get_lua_source());