Fix bug in mingw driver, work on lpxclient

This commit is contained in:
2021-11-03 11:11:31 -04:00
parent 9a02f408b0
commit 17a1155906
2 changed files with 53 additions and 10 deletions

View File

@@ -4,7 +4,9 @@
#include "world.hpp"
#include "luaconsole.hpp"
#include "invocation.hpp"
#include "util.hpp"
#include <memory>
#include <iostream>
class LpxClient : public DrivenEngine {
public:
@@ -17,13 +19,6 @@ public:
Gui gui_;
int64_t gui_place_;
void do_view_command(const StringVec &cmd);
void do_menu_command(const StringVec &cmd);
void do_choose_command(const StringVec &cmd);
void do_quit_command(const StringVec &cmd);
void do_lua(const std::string &exp);
void do_command(const StringVec &exp);
public:
virtual void event_init(int argc, char *argv[]) {
// Create the world model.
@@ -40,7 +35,52 @@ public:
channel_ = new_outgoing_channel("localhost:8085");
}
void do_lua(const std::string &lua) {
std::cerr << "Lua: " << lua << std::endl;
}
void do_command(const util::StringVec &words) {
std::cerr << "Command: ";
for (const std::string &word : words) {
std::cerr << word << " ";
}
std::cerr << std::endl;
}
void console_process(const std::string &line) {
console_.add(line);
int action = console_.action();
if (action == LuaConsole::DO_LUA) {
do_lua(console_.lua_expression());
console_.clear();
} else if (action == LuaConsole::DO_COMMAND) {
do_command(console_.words());
console_.clear();
} else if (action == LuaConsole::DO_SYNTAX) {
std::cerr << console_.syntax() << std::endl;
console_.clear();
}
}
virtual void event_update() {
// Check for keyboard input on stdin.
while (true) {
std::string line = get_stdio_channel()->in()->readline();
if (line == "") break;
console_process(line);
get_stdio_channel()->out()->write_bytes(console_.get_prompt());
}
// Check for communication from server..
if (channel_ != nullptr) {
if (channel_->closed()) {
std::cerr << "Server closed connection " << channel_->error() << std::endl;
channel_.reset();
// stop_driver();
} else {
// Implement reception of messages.
}
}
}
};