diff --git a/luprex/core/cpp/luaconsole.cpp b/luprex/core/cpp/luaconsole.cpp index 0c672a51..de8b6a83 100644 --- a/luprex/core/cpp/luaconsole.cpp +++ b/luprex/core/cpp/luaconsole.cpp @@ -4,10 +4,6 @@ #include "util.hpp" #include -static bool is_single_letter(const std::string &s) { - return ((s.size() == 1) && (s[0] >= 'a') && (s[0] <= 'z')); -} - LuaConsole::LuaConsole() { lua_state_ = luaL_newstate(); clear_raw_input(); @@ -57,16 +53,11 @@ void LuaConsole::add(std::string line) { lines_ += 1; prompt_ = ">> "; - // Try to interpret it as a special command. - if (lines_ == 1) { - StringVec words = split_words(raw_input_); - if (words.size() >= 1) { - if (is_single_letter(words[0]) || (util::validinteger(words[0]))) { - words_ = words; - clear_raw_input(); - return; - } - } + // Try to interpret it as a slash-command. + if ((lines_ == 1)&&(raw_input_[0] == '/')) { + words_ = split_words(raw_input_.substr(1)); + clear_raw_input(); + return; } // Translate lua expression with leading '=' to 'return' diff --git a/luprex/core/cpp/luaconsole.hpp b/luprex/core/cpp/luaconsole.hpp index f8a12f35..73cac7e8 100644 --- a/luprex/core/cpp/luaconsole.hpp +++ b/luprex/core/cpp/luaconsole.hpp @@ -10,19 +10,21 @@ // 3. Add the line to the LuaConsole using 'add'. // 4. Get the command words using 'get_command'. // 5. If the command is empty, do nothing. -// 6. If the command is nonempty, execute it and call 'clear'. +// 6. If the command is nonempty, execute it. // -// The 'words' returned by the luaconsole can be empty, meaning -// that there's no command to execute. If the words are nonempty, -// then the first word is the command. There are two hardwired -// commands: +// The LuaConsole expects you to type one of three things: // -// lua - execute a lua expression -// syntax - print a syntax error message +// * Valid Lua Code. +// * Valid Lua Code preceded by '=' as shorthand for 'return' +// * A slash-command. // -// If the first word is anything else, it means the user typed -// that word on the command line. It is up to you to interpret -// such commands. +// The 'get_command' returned by the luaconsole can be one of +// the following: +// +// empty vector - still collecting input: do nothing. +// lua - found a lua command: execute it as lua. +// syntax - detected a syntax error: print the error. +// word word ... - read a slash-command: execute the command. // //////////////////////////////////////////////////////