diff --git a/luprex/Makefile b/luprex/Makefile index 26a07a09..0cc56a3b 100644 --- a/luprex/Makefile +++ b/luprex/Makefile @@ -81,7 +81,7 @@ BASE_ERIS := \ BASE_CORE := \ 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 \ world-difftab world-diffxmit world-pairtab world-testing lpxserver lpxclient \ eng-tests printbuffer serializelua diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 27e5c21d..62d79fd1 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -164,10 +164,6 @@ SharedChannel DrivenEngine::get_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) { visible_world_ = w; visible_actor_id_ = id; @@ -369,11 +365,6 @@ bool DrivenEngine::drv_get_outgoing_empty(uint32_t chid) const { 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 { 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); } -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) { 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_outgoing = drv_get_outgoing; w->get_outgoing_empty = drv_get_outgoing_empty; - w->get_console_prompt = drv_get_console_prompt; w->get_clock = drv_get_clock; w->get_have_prints = drv_get_have_prints; w->get_rescan_lua_source = drv_get_rescan_lua_source; diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index 7a7abbc5..453987f4 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -205,10 +205,6 @@ public: // drv_sent_outgoing, drv_recv_incoming. // 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 // directory is read once, automatically, at engine creation time. @@ -277,7 +273,6 @@ public: bool drv_get_channel_released(uint32_t chid) const; void drv_get_outgoing(uint32_t chid, uint32_t *len, const char **data) 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; bool drv_get_have_prints() const; bool drv_get_rescan_lua_source() const; @@ -318,7 +313,6 @@ private: double clock_; bool have_prints_; bool stop_driver_; - eng::string console_prompt_; friend class Channel; }; diff --git a/luprex/cpp/core/enginewrapper.hpp b/luprex/cpp/core/enginewrapper.hpp index dbe8a9da..28dc81c2 100644 --- a/luprex/cpp/core/enginewrapper.hpp +++ b/luprex/cpp/core/enginewrapper.hpp @@ -34,6 +34,7 @@ enum class AccessKind { CONNECT_TO_SERVER, VALIDATE_LUA_EXPR, CHANNEL_PRINTS, + SLASH_COMMAND, }; class DrivenEngine; @@ -104,10 +105,6 @@ struct EngineWrapper { // 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 current time. This is equal to the last value passed diff --git a/luprex/cpp/core/lpxclient.cpp b/luprex/cpp/core/lpxclient.cpp index 689e3a23..8412a468 100644 --- a/luprex/cpp/core/lpxclient.cpp +++ b/luprex/cpp/core/lpxclient.cpp @@ -3,21 +3,18 @@ #include "drivenengine.hpp" #include "world.hpp" -#include "luaconsole.hpp" #include "invocation.hpp" #include "util.hpp" #include "printbuffer.hpp" #include -class LpxClient : public DrivenEngine, public CommonCommands { +class LpxClient : public DrivenEngine { public: - using StringVec = LuaConsole::StringVec; UniqueWorld world_; int64_t actor_id_; InvocationQueue unack_; SharedChannel channel_; - LuaConsole console_; PrintChanneler print_channeler_; eng::vector delayed_invocations_; lua_State *lua_syntax_checker_; @@ -26,8 +23,6 @@ public: LpxClient() { lua_syntax_checker_ = LuaCoreStack::newstate(eng::l_alloc); - set_console_prompt(console_.get_prompt()); - set_initial_state_standalone(); } @@ -134,55 +129,10 @@ public: } } - virtual void do_syntax_error(std::string_view error) override { - util::dprint("Syntax error: ", error, "\n"); - } - - 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 slash_command(std::string_view command) { + util::dprint("Slash Command: ", command); + // + // set_initial_state_connect(util::ss("nocert:", hostname, ":8085")); } void change_actor_id(int64_t actor_id) { @@ -279,6 +229,10 @@ public: set_have_prints(false); break; } + case AccessKind::SLASH_COMMAND: { + slash_command(datapk); + break; + } default: { util::dprint("Invalid event_access: ", int(kind)); } @@ -292,15 +246,6 @@ public: } 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.. if (channel_ != nullptr) { if (channel_->closed()) { diff --git a/luprex/cpp/core/lpxserver.cpp b/luprex/cpp/core/lpxserver.cpp index 3796977b..5d1ba175 100644 --- a/luprex/cpp/core/lpxserver.cpp +++ b/luprex/cpp/core/lpxserver.cpp @@ -3,7 +3,6 @@ #include "world.hpp" #include "drivenengine.hpp" -#include "luaconsole.hpp" #include "util.hpp" #include "printbuffer.hpp" #include "luastack.hpp" @@ -22,11 +21,9 @@ public: using UniqueClient = std::unique_ptr; using ClientVector = eng::vector; -class LpxServer : public DrivenEngine, public CommonCommands { +class LpxServer : public DrivenEngine { public: - using StringVec = LuaConsole::StringVec; UniqueWorld master_; - LuaConsole console_; ClientVector clients_; PrintChanneler print_channeler_; HttpChannelMap http_client_channels_; @@ -57,9 +54,6 @@ public: // Enable listening on port 8080 (http server connections) listen_port(8080); - // Set the console prompt. - set_console_prompt(console_.get_prompt()); - // Export stuff to the graphics engine. set_visible_world_and_actor(master_.get(), admin_id_); @@ -74,54 +68,9 @@ public: lua_close(lua_syntax_checker_); } - virtual void do_syntax_error(std::string_view error) override { - util::dprint("Syntax error: ", error, "\n"); - } - - 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 slash_command(std::string_view command) + { + util::dprint("Slash Command:", command); } void delete_client(UniqueClient &client) { @@ -205,6 +154,10 @@ public: set_have_prints(false); break; } + case AccessKind::SLASH_COMMAND: { + slash_command(datapk); + break; + } default: { util::dprint("Invalid event_access: ", int(kind)); } @@ -222,15 +175,6 @@ public: } 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. while (true) { SharedChannel chan = new_incoming_channel(); diff --git a/luprex/cpp/core/luaconsole.cpp b/luprex/cpp/core/luaconsole.cpp index 324210f7..8e09928e 100644 --- a/luprex/cpp/core/luaconsole.cpp +++ b/luprex/cpp/core/luaconsole.cpp @@ -9,12 +9,10 @@ #include LuaConsole::LuaConsole() { - lua_state_ = LuaCoreStack::newstate(eng::l_alloc); clear_raw_input(); } LuaConsole::~LuaConsole() { - lua_close(lua_state_); } 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]); -} diff --git a/luprex/cpp/core/luaconsole.hpp b/luprex/cpp/core/luaconsole.hpp index 2fca16c2..9fdefb30 100644 --- a/luprex/cpp/core/luaconsole.hpp +++ b/luprex/cpp/core/luaconsole.hpp @@ -47,16 +47,11 @@ #include "luastack.hpp" -class LuaConsole : public eng::nevernew { -public: - using StringVec = eng::vector; - +class LuaConsole { private: - lua_State *lua_state_; eng::string raw_input_; int lines_; eng::string prompt_; - StringVec words_; void clear_raw_input(); @@ -79,40 +74,4 @@ public: 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; - -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 diff --git a/luprex/cpp/drv/driver.cpp b/luprex/cpp/drv/driver.cpp index abd1018e..9da61e68 100644 --- a/luprex/cpp/drv/driver.cpp +++ b/luprex/cpp/drv/driver.cpp @@ -214,10 +214,7 @@ class Driver { void handle_console_input() { read_console_recently_ = false; - uint32_t promptlen; - const char *promptdata; - engw.get_console_prompt(&engw, &promptlen, &promptdata); - std::u32string prompt = drvutil::utf8_to_utf32(std::string_view(promptdata, promptlen), nullptr); + std::u32string prompt = drvutil::utf8_to_utf32(">", nullptr); readline_device_.set_prompt(prompt); while (true) { std::u32string cps = console_read();