Do a refactor of command parsing in lpxclient and lpxserver
This commit is contained in:
@@ -59,8 +59,6 @@ private:
|
||||
StringVec words_;
|
||||
|
||||
void clear_raw_input();
|
||||
void simplify(const StringVec &words);
|
||||
void synerr(const eng::string &msg);
|
||||
|
||||
public:
|
||||
LuaConsole();
|
||||
@@ -74,16 +72,49 @@ public:
|
||||
|
||||
// Get the command words.
|
||||
//
|
||||
// Note that the command words may not be exactly what
|
||||
// the user typed. Typically, the LuaConsole simplifies
|
||||
// the command before returning it to the caller.
|
||||
//
|
||||
StringVec get_command();
|
||||
|
||||
// Add a line of text that was just read from the console.
|
||||
//
|
||||
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_choose_command(int64_t n) = 0;
|
||||
virtual void do_view_command() = 0;
|
||||
virtual void do_moveto_command(int x, int y) = 0;
|
||||
virtual void do_menu_command(int64_t tanid) = 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
|
||||
|
||||
Reference in New Issue
Block a user