Stop channeling printbuffers to stdostream. Instead, provide an invocation CHANNEL_PRINTS.

This commit is contained in:
2025-12-15 22:22:03 -05:00
parent a0703effc3
commit f528ba69fe
6 changed files with 24 additions and 16 deletions

View File

@@ -33,6 +33,7 @@ enum class AccessKind {
PROBE_LUA_CALL, PROBE_LUA_CALL,
CONNECT_TO_SERVER, CONNECT_TO_SERVER,
VALIDATE_LUA_EXPR, VALIDATE_LUA_EXPR,
CHANNEL_PRINTS,
}; };
class DrivenEngine; class DrivenEngine;

View File

@@ -270,6 +270,13 @@ public:
retpk->write_bytes(errmsg); retpk->write_bytes(errmsg);
break; break;
} }
case AccessKind::CHANNEL_PRINTS: {
world_to_asynchronous();
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
send_invocation(print_channeler_.invocation(actor_id_));
}
break;
}
default: { default: {
util::dprint("Invalid event_access: ", int(kind)); util::dprint("Invalid event_access: ", int(kind));
} }
@@ -305,11 +312,6 @@ public:
world_to_asynchronous(); world_to_asynchronous();
} }
} }
// Channel print statements.
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), stdostream())) {
send_invocation(print_channeler_.invocation(actor_id_));
}
} }
}; };

View File

@@ -63,6 +63,9 @@ public:
// Export stuff to the graphics engine. // Export stuff to the graphics engine.
set_visible_world_and_actor(master_.get(), admin_id_); set_visible_world_and_actor(master_.get(), admin_id_);
// Reset the print channeler.
print_channeler_.reset();
// Trigger the loading of the lua source. // Trigger the loading of the lua source.
rescan_lua_source(true); rescan_lua_source(true);
} }
@@ -194,6 +197,12 @@ public:
retpk->write_bytes(errmsg); retpk->write_bytes(errmsg);
break; break;
} }
case AccessKind::CHANNEL_PRINTS: {
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), retpk)) {
master_->invoke(print_channeler_.invocation(admin_id_));
}
break;
}
default: { default: {
stdostream() << "Invalid event_access: " << int(kind) << std::endl; stdostream() << "Invalid event_access: " << int(kind) << std::endl;
} }
@@ -220,11 +229,6 @@ public:
do_command(console_.get_command()); do_command(console_.get_command());
} }
// Anything in the administrator printbuffer should go to stdostream.
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), stdostream())) {
master_->invoke(print_channeler_.invocation(admin_id_));
}
// Check for new incoming channels, set up client structures. // Check for new incoming channels, set up client structures.
while (true) { while (true) {
SharedChannel chan = new_incoming_channel(); SharedChannel chan = new_incoming_channel();

View File

@@ -91,7 +91,7 @@ void LuaConsole::add(eng::string line) {
// Try to parse the lua expression // Try to parse the lua expression
{ {
LuaVar result; LuaVar result;
LuaDefStack LS(lua_state_, result); LuaExtStack LS(lua_state_, result);
eng::string errmsg = LS.load(result, partial, "stdin"); eng::string errmsg = LS.load(result, partial, "stdin");
if (errmsg.empty()) { if (errmsg.empty()) {
words_.push_back(lua_mode); words_.push_back(lua_mode);

View File

@@ -17,8 +17,7 @@ struct PrintBufferCore : public eng::opnew {
// Line number of the first unchecked line in the buffer. All line // Line number of the first unchecked line in the buffer. All line
// numbers including this one and beyond are unchecked. // numbers including this one and beyond are unchecked.
// "Unchecked" lines are lines in a non-authoritative model // "Unchecked" lines are lines in a non-authoritative model
// that haven't been verified through difference transmission. // that haven't been verified through difference transmission
int first_unchecked_; int first_unchecked_;
// Constructor. // Constructor.
@@ -180,13 +179,15 @@ void PrintBuffer::patch(StreamBuffer *sb, DebugCollector *dbc) {
} }
} }
bool PrintChanneler::channel(const PrintBuffer *printbuffer, std::ostream &ostream) { bool PrintChanneler::channel(const PrintBuffer *printbuffer, StreamBuffer *sb) {
if (printbuffer == nullptr) return false; if (printbuffer == nullptr) return false;
if (printbuffer->first_line() > line_) { if (printbuffer->first_line() > line_) {
line_ = printbuffer->first_line(); line_ = printbuffer->first_line();
} }
while (line_ < printbuffer->first_unchecked()) { while (line_ < printbuffer->first_unchecked()) {
ostream << "|" << printbuffer->nth(line_) << std::endl; sb->write_bytes("|");
sb->write_bytes(printbuffer->nth(line_));
sb->write_bytes("\n");
line_ += 1; line_ += 1;
} }
return line_ > printbuffer->first_line(); return line_ > printbuffer->first_line();

View File

@@ -152,7 +152,7 @@ public:
// Copy any new lines from the printbuffer to the stdostream. // Copy any new lines from the printbuffer to the stdostream.
// Update the current line number. Return true if the printbuffer // Update the current line number. Return true if the printbuffer
// contains any lines that have already been channeled. // contains any lines that have already been channeled.
bool channel(const PrintBuffer *pb, std::ostream &ostream); bool channel(const PrintBuffer *pb, StreamBuffer *sb);
// Generate an invocation that removes unnecessary lines from the // Generate an invocation that removes unnecessary lines from the
// printbuffer. // printbuffer.