diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 62d79fd1..5e2d7b00 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -37,7 +37,9 @@ DrivenEngineInitializerReg::DrivenEngineInitializerReg(DrivenEngineInitializer f ////////////////////////////////////////////////////////////////////////////// int DrivenEngine::find_unused_chid() { - // Note: channel ID zero is special, it is never reused. + // Note: channel ID zero is never used. Channel ID 0 used to be + // reserved for the stdio channel. When we eliminated the stdio + // channel, we blocked off ID 0 permanently. for (int i = 0; i < DRV_MAX_CHAN; i++) { int id = next_unused_chid_++; if (next_unused_chid_ == DRV_MAX_CHAN) next_unused_chid_ = 1; @@ -48,6 +50,7 @@ int DrivenEngine::find_unused_chid() { } Channel *DrivenEngine::get_chid(int chid) const { + assert(chid != 0); assert(unsigned(chid) < DRV_MAX_CHAN); assert(channels_[chid].get() != nullptr); return channels_[chid].get(); @@ -160,10 +163,6 @@ SharedChannel DrivenEngine::new_incoming_channel() { } } -SharedChannel DrivenEngine::get_stdio_channel() { - return stdio_channel_; -} - void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) { visible_world_ = w; visible_actor_id_ = id; @@ -180,8 +179,6 @@ void DrivenEngine::stop_driver() { DrivenEngine::DrivenEngine() { next_unused_chid_ = 1; - stdio_channel_ = eng::make_shared(this, 0, 0, "", false); - channels_[0] = stdio_channel_; rescan_lua_source_ = false; clock_ = 0.0; have_prints_ = false; diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index 453987f4..502bef0c 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -196,16 +196,6 @@ public: // SharedChannel new_incoming_channel(); - // Obtain the stdio channel. There is only one stdio channel. - // - // DRIVER: the stdio channel is created automatically when the DrivenEngine - // is created. Stdio should be connected to a console which is in - // line-at-a-time mode. The driver is responsible for relaying data from - // the console into the stdio channel using drv_peek_outgoing, - // drv_sent_outgoing, drv_recv_incoming. - // - SharedChannel get_stdio_channel(); - // Set the flag to rescan the lua source directory. The lua source // directory is read once, automatically, at engine creation time. // If you want to read it again, you must trigger a rescan. @@ -300,7 +290,6 @@ private: private: SharedChannel channels_[DRV_MAX_CHAN]; int next_unused_chid_; - SharedChannel stdio_channel_; eng::vector accepted_channels_; eng::vector new_outgoing_; eng::vector listen_ports_; diff --git a/luprex/cpp/core/eng-tests.cpp b/luprex/cpp/core/eng-tests.cpp index 42ac95a6..d78d3e44 100644 --- a/luprex/cpp/core/eng-tests.cpp +++ b/luprex/cpp/core/eng-tests.cpp @@ -6,19 +6,15 @@ #include -static void write_closed_message(Channel *ch, StreamBuffer *out) { - eng::ostringstream oss; - oss << "Chan " << ch->chid() << " closed [" << ch->error() << "]\n"; - out->write_bytes(oss.str()); +static void write_closed_message(Channel *ch) { + util::dprint("Chan ", ch->chid(), " closed [", ch->error(), "]\n"); } -static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) { +static void dump_lines(StreamBuffer *in, int chid) { while (true) { eng::string l = in->readline(); if (l == "") break; - eng::ostringstream oss; - oss << "Chan " << chid << ": " << l; - out->write_bytes(oss.str()); + util::dprint("Chan ", chid, ": ", l); } } @@ -34,13 +30,11 @@ public: } virtual void event_update() override { - SharedChannel stdioch = get_stdio_channel(); - dump_lines(stdioch->in(), stdioch->out(), 0); eng::vector keep; for (SharedChannel &ch : channels_) { - dump_lines(ch->in(), stdioch->out(), ch->chid()); + dump_lines(ch->in(), ch->chid()); if (ch->closed()) { - write_closed_message(ch.get(), stdioch->out()); + write_closed_message(ch.get()); } else { keep.emplace_back(std::move(ch)); } @@ -60,13 +54,11 @@ public: } virtual void event_update() override { - SharedChannel stdioch = get_stdio_channel(); - dump_lines(stdioch->in(), stdioch->out(), 0); eng::vector keep; for (SharedChannel &ch : channels_) { - dump_lines(ch->in(), stdioch->out(), ch->chid()); + dump_lines(ch->in(), ch->chid()); if (ch->closed()) { - write_closed_message(ch.get(), stdioch->out()); + write_closed_message(ch.get()); } else { keep.emplace_back(std::move(ch)); }