Pass argc and argv through to DrivenEngine::event_init

This commit is contained in:
2021-10-14 16:41:24 -04:00
parent a9afbebbc3
commit 2e05df7ac5
9 changed files with 21 additions and 19 deletions

View File

@@ -207,8 +207,8 @@ void DrivenEngine::drv_set_lua_source(util::LuaSourcePtr source) {
rescan_lua_source_ = false; rescan_lua_source_ = false;
} }
void DrivenEngine::drv_invoke_event_init() { void DrivenEngine::drv_invoke_event_init(int argc, char *argv[]) {
event_init(); event_init(argc, argv);
} }
void DrivenEngine::drv_invoke_event_update() { void DrivenEngine::drv_invoke_event_update() {

View File

@@ -191,7 +191,7 @@ public:
// The update callback. You may override this in a subclass. // The update callback. You may override this in a subclass.
// This will be called whenever anything changes. // This will be called whenever anything changes.
// //
virtual void event_init() {} virtual void event_init(int argc, char *argv[]) {}
virtual void event_update() {} virtual void event_update() {}
// Specify the set of listening ports. // Specify the set of listening ports.
@@ -343,7 +343,7 @@ public:
// Invoke the init or update event. // 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(); void drv_invoke_event_update();
// Check the 'rescan_lua_source' flag. If this flag is set, it means // Check the 'rescan_lua_source' flag. If this flag is set, it means

View File

@@ -325,7 +325,7 @@ public:
} }
} }
void drive(DrivenEngine *de) { void drive(DrivenEngine *de, int argc, char *argv[]) {
WSADATA whocares; WSADATA whocares;
assert(WSAStartup(MAKEWORD(2,2), &whocares) == 0); assert(WSAStartup(MAKEWORD(2,2), &whocares) == 0);
HANDLE hconsole = GetStdHandle(STD_INPUT_HANDLE); HANDLE hconsole = GetStdHandle(STD_INPUT_HANDLE);
@@ -334,7 +334,7 @@ public:
DrivenEngine::set(de); DrivenEngine::set(de);
basetime_ = get_now(); basetime_ = get_now();
driven_->drv_set_lua_source(util::read_lua_source("lua")); 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(); handle_listen_ports();
while (!de->drv_get_stop_driver()) { while (!de->drv_get_stop_driver()) {
short_sleep_ = false; 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 driver;
driver.drive(de); driver.drive(de, argc, argv);
} }

View File

@@ -3,6 +3,6 @@
#include "drivenengine.hpp" #include "drivenengine.hpp"
void driver_drive(DrivenEngine *de); void driver_drive(DrivenEngine *de, int argc, char *argv[]);
#endif // DRIVER_HPP #endif // DRIVER_HPP

View File

@@ -24,7 +24,7 @@ static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) {
class DriverListenTest : public DrivenEngine { class DriverListenTest : public DrivenEngine {
public: public:
std::vector<UniqueChannel> channels_; std::vector<UniqueChannel> channels_;
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
listen_port(8085); listen_port(8085);
} }
@@ -56,7 +56,7 @@ public:
class DriverWebServerTest : public DrivenEngine { class DriverWebServerTest : public DrivenEngine {
public: public:
std::vector<UniqueChannel> channels_; std::vector<UniqueChannel> channels_;
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
UniqueChannel ch = new_outgoing_channel("stanford.edu:80"); UniqueChannel ch = new_outgoing_channel("stanford.edu:80");
ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n");
channels_.emplace_back(std::move(ch)); channels_.emplace_back(std::move(ch));
@@ -82,7 +82,7 @@ public:
class DriverDNSFailTest : public DrivenEngine { class DriverDNSFailTest : public DrivenEngine {
public: public:
std::vector<UniqueChannel> channels_; std::vector<UniqueChannel> channels_;
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
UniqueChannel ch = new_outgoing_channel("akjsdkajshdakjshd.alk:80"); UniqueChannel ch = new_outgoing_channel("akjsdkajshdakjshd.alk:80");
ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n"); ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n");
channels_.emplace_back(std::move(ch)); channels_.emplace_back(std::move(ch));
@@ -108,7 +108,7 @@ public:
class DriverPrintClockTest : public DrivenEngine { class DriverPrintClockTest : public DrivenEngine {
public: public:
int count; int count;
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
count = 0; count = 0;
} }

View File

@@ -25,7 +25,7 @@ public:
void do_command(const StringVec &exp); void do_command(const StringVec &exp);
public: public:
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
} }
virtual void event_update() { virtual void event_update() {

View File

@@ -17,7 +17,7 @@ public:
std::vector<std::unique_ptr<ServerClient>> clients_; std::vector<std::unique_ptr<ServerClient>> clients_;
public: public:
virtual void event_init() { virtual void event_init(int argc, char *argv[]) {
} }
virtual void event_update() { virtual void event_update() {

View File

@@ -33,7 +33,7 @@ static void usage() {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
UniqueDrivenEngine engine; UniqueDrivenEngine engine;
if (argc != 2) usage(); if (argc < 2) usage();
std::string mode = argv[1]; std::string mode = argv[1];
for (int i = 0; makers[i].name != nullptr; i++) { for (int i = 0; makers[i].name != nullptr; i++) {
if (mode == makers[i].name) { if (mode == makers[i].name) {
@@ -42,6 +42,8 @@ int main(int argc, char **argv)
} }
} }
if (engine == nullptr) usage(); 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);
} }

View File

@@ -41,7 +41,7 @@ private:
void check_redirects(); void check_redirects();
public: public:
virtual void event_init(); virtual void event_init(int argc, char *argv[]);
virtual void event_update(); 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_.reset(new World(util::WORLD_TYPE_STANDALONE));
world_->update_source(get_lua_source()); world_->update_source(get_lua_source());