luaconsole.cpp has been removed. Ascii driver is still sending text via stdin, but it is now ignored. So in ascii mode, commands are currently not interpreted.

This commit is contained in:
2025-12-16 00:34:30 -05:00
parent c0bcb1099b
commit f75ff36c3d
9 changed files with 21 additions and 288 deletions

View File

@@ -81,7 +81,7 @@ BASE_ERIS := \
BASE_CORE := \ BASE_CORE := \
invocation spookyv2 eng-malloc debugcollector drivenengine util luastack \ invocation spookyv2 eng-malloc debugcollector drivenengine util luastack \
traceback planemap pprint luaconsole luavector idalloc globaldb sched http \ traceback planemap pprint luavector idalloc globaldb sched http \
json table luasnap animqueue streambuffer source world-core world-accessor \ json table luasnap animqueue streambuffer source world-core world-accessor \
world-difftab world-diffxmit world-pairtab world-testing lpxserver lpxclient \ world-difftab world-diffxmit world-pairtab world-testing lpxserver lpxclient \
eng-tests printbuffer serializelua eng-tests printbuffer serializelua

View File

@@ -164,10 +164,6 @@ SharedChannel DrivenEngine::get_stdio_channel() {
return stdio_channel_; return stdio_channel_;
} }
void DrivenEngine::set_console_prompt(const eng::string &prompt) {
console_prompt_ = prompt;
}
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) { void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
visible_world_ = w; visible_world_ = w;
visible_actor_id_ = id; visible_actor_id_ = id;
@@ -369,11 +365,6 @@ bool DrivenEngine::drv_get_outgoing_empty(uint32_t chid) const {
return (v.size() == 0); return (v.size() == 0);
} }
void DrivenEngine::drv_get_console_prompt(uint32_t *len, const char **data) const {
*len = console_prompt_.size();
*data = console_prompt_.c_str();
}
double DrivenEngine::drv_get_clock() const { double DrivenEngine::drv_get_clock() const {
return clock_; return clock_;
} }
@@ -529,10 +520,6 @@ static bool drv_get_outgoing_empty(EngineWrapper *w, uint32_t chid) {
return w->engine->drv_get_outgoing_empty(chid); return w->engine->drv_get_outgoing_empty(chid);
} }
static void drv_get_console_prompt(EngineWrapper *w, uint32_t *len, const char **data) {
return w->engine->drv_get_console_prompt(len, data);
}
static double drv_get_clock(EngineWrapper *w) { static double drv_get_clock(EngineWrapper *w) {
return w->engine->drv_get_clock(); return w->engine->drv_get_clock();
} }
@@ -916,7 +903,6 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
w->get_channel_released = drv_get_channel_released; w->get_channel_released = drv_get_channel_released;
w->get_outgoing = drv_get_outgoing; w->get_outgoing = drv_get_outgoing;
w->get_outgoing_empty = drv_get_outgoing_empty; w->get_outgoing_empty = drv_get_outgoing_empty;
w->get_console_prompt = drv_get_console_prompt;
w->get_clock = drv_get_clock; w->get_clock = drv_get_clock;
w->get_have_prints = drv_get_have_prints; w->get_have_prints = drv_get_have_prints;
w->get_rescan_lua_source = drv_get_rescan_lua_source; w->get_rescan_lua_source = drv_get_rescan_lua_source;

View File

@@ -206,10 +206,6 @@ public:
// //
SharedChannel get_stdio_channel(); SharedChannel get_stdio_channel();
// Set the prompt for the console.
//
void set_console_prompt(const eng::string &prompt);
// Set the flag to rescan the lua source directory. The lua source // Set the flag to rescan the lua source directory. The lua source
// directory is read once, automatically, at engine creation time. // directory is read once, automatically, at engine creation time.
// If you want to read it again, you must trigger a rescan. // If you want to read it again, you must trigger a rescan.
@@ -277,7 +273,6 @@ public:
bool drv_get_channel_released(uint32_t chid) const; bool drv_get_channel_released(uint32_t chid) const;
void drv_get_outgoing(uint32_t chid, uint32_t *len, const char **data) const; void drv_get_outgoing(uint32_t chid, uint32_t *len, const char **data) const;
bool drv_get_outgoing_empty(uint32_t chid) const; bool drv_get_outgoing_empty(uint32_t chid) const;
void drv_get_console_prompt(uint32_t *len, const char **data) const;
double drv_get_clock() const; double drv_get_clock() const;
bool drv_get_have_prints() const; bool drv_get_have_prints() const;
bool drv_get_rescan_lua_source() const; bool drv_get_rescan_lua_source() const;
@@ -318,7 +313,6 @@ private:
double clock_; double clock_;
bool have_prints_; bool have_prints_;
bool stop_driver_; bool stop_driver_;
eng::string console_prompt_;
friend class Channel; friend class Channel;
}; };

View File

@@ -34,6 +34,7 @@ enum class AccessKind {
CONNECT_TO_SERVER, CONNECT_TO_SERVER,
VALIDATE_LUA_EXPR, VALIDATE_LUA_EXPR,
CHANNEL_PRINTS, CHANNEL_PRINTS,
SLASH_COMMAND,
}; };
class DrivenEngine; class DrivenEngine;
@@ -104,10 +105,6 @@ struct EngineWrapper {
// //
bool (*get_outgoing_empty)(EngineWrapper *w, uint32_t chid); bool (*get_outgoing_empty)(EngineWrapper *w, uint32_t chid);
// Get the console prompt.
//
void (*get_console_prompt)(EngineWrapper *w, uint32_t *len, const char **data);
// Get the clock. // Get the clock.
// //
// Get the current time. This is equal to the last value passed // Get the current time. This is equal to the last value passed

View File

@@ -3,21 +3,18 @@
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "world.hpp" #include "world.hpp"
#include "luaconsole.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include "util.hpp" #include "util.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include <memory> #include <memory>
class LpxClient : public DrivenEngine, public CommonCommands { class LpxClient : public DrivenEngine {
public: public:
using StringVec = LuaConsole::StringVec;
UniqueWorld world_; UniqueWorld world_;
int64_t actor_id_; int64_t actor_id_;
InvocationQueue unack_; InvocationQueue unack_;
SharedChannel channel_; SharedChannel channel_;
LuaConsole console_;
PrintChanneler print_channeler_; PrintChanneler print_channeler_;
eng::vector<Invocation> delayed_invocations_; eng::vector<Invocation> delayed_invocations_;
lua_State *lua_syntax_checker_; lua_State *lua_syntax_checker_;
@@ -26,8 +23,6 @@ public:
LpxClient() { LpxClient() {
lua_syntax_checker_ = LuaCoreStack::newstate(eng::l_alloc); lua_syntax_checker_ = LuaCoreStack::newstate(eng::l_alloc);
set_console_prompt(console_.get_prompt());
set_initial_state_standalone(); set_initial_state_standalone();
} }
@@ -134,55 +129,10 @@ public:
} }
} }
virtual void do_syntax_error(std::string_view error) override { void slash_command(std::string_view command) {
util::dprint("Syntax error: ", error, "\n"); util::dprint("Slash Command: ", command);
} //
// set_initial_state_connect(util::ss("nocert:", hostname, ":8085"));
virtual void do_unknown_command(std::string_view name) override {
util::dprint("Unknown command: ", name);
}
virtual void do_view_command() override {
util::dprint(world_->tangibles_near_debug_string(actor_id_, 1000));
}
virtual void do_moveto_command(int x, int y) override {
do_unknown_command("moveto");
}
virtual void do_quit_command() override {
abandon_server();
stop_driver();
}
virtual void do_cpl_command() override {
rescan_lua_source(true);
}
virtual void do_work_command() override {
do_unknown_command("work");
}
virtual void do_display_command() override {
do_unknown_command("display");
}
virtual void do_aborthttp_command() override {
do_unknown_command("aborthttp");
}
virtual void do_connect_command(std::string_view hostname) override {
set_initial_state_connect(util::ss("nocert:", hostname, ":8085"));
}
virtual void do_luainvoke_command(std::string_view cmd) override {
send_invocation(Invocation(AccessKind::INVOKE_LUA_EXPR, actor_id_, actor_id_, cmd));
}
virtual void do_luaprobe_command(std::string_view cmd) override {
world_to_asynchronous();
util::dprint(world_->probe_lua_expr(actor_id_, cmd));
world_to_synchronous();
} }
void change_actor_id(int64_t actor_id) { void change_actor_id(int64_t actor_id) {
@@ -279,6 +229,10 @@ public:
set_have_prints(false); set_have_prints(false);
break; break;
} }
case AccessKind::SLASH_COMMAND: {
slash_command(datapk);
break;
}
default: { default: {
util::dprint("Invalid event_access: ", int(kind)); util::dprint("Invalid event_access: ", int(kind));
} }
@@ -292,15 +246,6 @@ public:
} }
delayed_invocations_.clear(); delayed_invocations_.clear();
// Check for keyboard input on stdin.
while (true) {
eng::string line = get_stdio_channel()->in()->readline();
if (line == "") break;
console_.add(line);
set_console_prompt(console_.get_prompt());
do_command(console_.get_command());
}
// Check for communication from server.. // Check for communication from server..
if (channel_ != nullptr) { if (channel_ != nullptr) {
if (channel_->closed()) { if (channel_->closed()) {

View File

@@ -3,7 +3,6 @@
#include "world.hpp" #include "world.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "luaconsole.hpp"
#include "util.hpp" #include "util.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include "luastack.hpp" #include "luastack.hpp"
@@ -22,11 +21,9 @@ public:
using UniqueClient = std::unique_ptr<Client>; using UniqueClient = std::unique_ptr<Client>;
using ClientVector = eng::vector<UniqueClient>; using ClientVector = eng::vector<UniqueClient>;
class LpxServer : public DrivenEngine, public CommonCommands { class LpxServer : public DrivenEngine {
public: public:
using StringVec = LuaConsole::StringVec;
UniqueWorld master_; UniqueWorld master_;
LuaConsole console_;
ClientVector clients_; ClientVector clients_;
PrintChanneler print_channeler_; PrintChanneler print_channeler_;
HttpChannelMap http_client_channels_; HttpChannelMap http_client_channels_;
@@ -57,9 +54,6 @@ public:
// Enable listening on port 8080 (http server connections) // Enable listening on port 8080 (http server connections)
listen_port(8080); listen_port(8080);
// Set the console prompt.
set_console_prompt(console_.get_prompt());
// 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_);
@@ -74,54 +68,9 @@ public:
lua_close(lua_syntax_checker_); lua_close(lua_syntax_checker_);
} }
virtual void do_syntax_error(std::string_view error) override { void slash_command(std::string_view command)
util::dprint("Syntax error: ", error, "\n"); {
} util::dprint("Slash Command:", command);
virtual void do_unknown_command(std::string_view name) override {
util::dprint("Unknown command: ", name, "\n");
}
virtual void do_view_command() override {
util::dprint(master_->tangibles_near_debug_string(admin_id_, 1000));
}
virtual void do_moveto_command(int x, int y) override {
do_unknown_command("moveto");
}
virtual void do_quit_command() override {
stop_driver();
}
virtual void do_cpl_command() override {
rescan_lua_source(true);
}
virtual void do_work_command() override {
do_unknown_command("work");
}
virtual void do_display_command() override {
do_unknown_command("display");
}
virtual void do_aborthttp_command() override {
master_->abort_all_http_requests(425, "http requests aborted from the server command line");
}
virtual void do_connect_command(std::string_view hostname) override {
do_unknown_command("connect");
}
virtual void do_luainvoke_command(std::string_view cmd) override {
master_->invoke(Invocation(AccessKind::INVOKE_LUA_EXPR, admin_id_, admin_id_, cmd));
}
virtual void do_luaprobe_command(std::string_view cmd) override {
master_->snapshot();
util::dprint(master_->probe_lua_expr(admin_id_, cmd));
master_->rollback();
} }
void delete_client(UniqueClient &client) { void delete_client(UniqueClient &client) {
@@ -205,6 +154,10 @@ public:
set_have_prints(false); set_have_prints(false);
break; break;
} }
case AccessKind::SLASH_COMMAND: {
slash_command(datapk);
break;
}
default: { default: {
util::dprint("Invalid event_access: ", int(kind)); util::dprint("Invalid event_access: ", int(kind));
} }
@@ -222,15 +175,6 @@ public:
} }
delayed_invocations_.clear(); delayed_invocations_.clear();
// Check for keyboard input on stdin.
while (true) {
eng::string line = get_stdio_channel()->in()->readline();
if (line == "") break;
console_.add(line);
set_console_prompt(console_.get_prompt());
do_command(console_.get_command());
}
// 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

@@ -9,12 +9,10 @@
#include <iostream> #include <iostream>
LuaConsole::LuaConsole() { LuaConsole::LuaConsole() {
lua_state_ = LuaCoreStack::newstate(eng::l_alloc);
clear_raw_input(); clear_raw_input();
} }
LuaConsole::~LuaConsole() { LuaConsole::~LuaConsole() {
lua_close(lua_state_);
} }
static LuaConsole::StringVec split_words(const eng::string &raw) { static LuaConsole::StringVec split_words(const eng::string &raw) {
@@ -108,90 +106,3 @@ void LuaConsole::add(eng::string line) {
} }
} }
void CommonCommands::do_command(const StringVec &words) {
if (words.size() == 0) {
return;
}
if (words[0] == "view") {
if (words.size() == 1) {
return do_view_command();
} else {
return do_syntax_error("/view takes no arguments");
}
}
if (words[0] == "moveto") {
if ((words.size() == 3) && sv::valid_int64(words[1]) && sv::valid_int64(words[2])) {
return do_moveto_command(sv::to_int64(words[1]), sv::to_int64(words[2]));
} else {
return do_syntax_error("/moveto [x] [y]");
}
}
if (words[0] == "quit") {
if (words.size() == 1) {
return do_quit_command();
} else {
return do_syntax_error("/quit takes no arguments");
}
}
if (words[0] == "cpl") {
if (words.size() == 1) {
return do_cpl_command();
} else {
return do_syntax_error("/cpl takes no arguments");
}
}
if (words[0] == "work") {
if (words.size() == 1) {
return do_work_command();
} else {
return do_syntax_error("/work takes no arguments");
}
}
if (words[0] == "display") {
if (words.size() == 1) {
return do_display_command();
} else {
return do_syntax_error("/display takes no arguments");
}
}
if (words[0] == "aborthttp") {
if (words.size() == 1) {
return do_aborthttp_command();
} else {
return do_syntax_error("/aborthttp takes no arguments");
}
}
if (words[0] == "connect") {
if ((words.size() == 2)&&(sv::valid_hostname(words[1]))) {
return do_connect_command(words[1]);
} else {
return do_syntax_error("/connect [hostname]");
}
}
if (words[0] == "luainvoke") {
if (words.size() == 2) {
return do_luainvoke_command(words[1]);
} else {
return do_syntax_error("/luainvoke [command]");
}
}
if (words[0] == "luaprobe") {
if (words.size() == 2) {
return do_luaprobe_command(words[1]);
} else {
return do_syntax_error("/luainvoke [command]");
}
}
return do_unknown_command(words[0]);
}

View File

@@ -47,16 +47,11 @@
#include "luastack.hpp" #include "luastack.hpp"
class LuaConsole : public eng::nevernew { class LuaConsole {
public:
using StringVec = eng::vector<eng::string>;
private: private:
lua_State *lua_state_;
eng::string raw_input_; eng::string raw_input_;
int lines_; int lines_;
eng::string prompt_; eng::string prompt_;
StringVec words_;
void clear_raw_input(); void clear_raw_input();
@@ -79,40 +74,4 @@ public:
void add(eng::string line); void add(eng::string line);
}; };
//////////////////////////////////////////////////////
//
// CommonCommands is parses slash-commands that are understood by
// lpxclient and lpxserver. That way, these two separate
// sourcefiles don't have to duplicate the code for parsing.
//
// After parsing, this module calls a virtual function
// to execute the command. lpxserver and lpxclient
// implement these virtual functions in different ways.
//
//////////////////////////////////////////////////////
class CommonCommands {
public:
using StringVec = eng::vector<eng::string>;
protected:
virtual void do_syntax_error(std::string_view error) = 0;
virtual void do_unknown_command(std::string_view name) = 0;
virtual void do_view_command() = 0;
virtual void do_moveto_command(int x, int y) = 0;
virtual void do_quit_command() = 0;
virtual void do_cpl_command() = 0;
virtual void do_work_command() = 0;
virtual void do_display_command() = 0;
virtual void do_aborthttp_command() = 0;
virtual void do_connect_command(std::string_view hostname) = 0;
virtual void do_luainvoke_command(std::string_view cmd) = 0;
virtual void do_luaprobe_command(std::string_view cmd) = 0;
public:
// Parse a command and call one of the virtual command functions above.
//
void do_command(const StringVec &command);
};
#endif // LUACONSOLE_HPP #endif // LUACONSOLE_HPP

View File

@@ -214,10 +214,7 @@ class Driver {
void handle_console_input() { void handle_console_input() {
read_console_recently_ = false; read_console_recently_ = false;
uint32_t promptlen; std::u32string prompt = drvutil::utf8_to_utf32(">", nullptr);
const char *promptdata;
engw.get_console_prompt(&engw, &promptlen, &promptdata);
std::u32string prompt = drvutil::utf8_to_utf32(std::string_view(promptdata, promptlen), nullptr);
readline_device_.set_prompt(prompt); readline_device_.set_prompt(prompt);
while (true) { while (true) {
std::u32string cps = console_read(); std::u32string cps = console_read();