Refactor luaconsole to make it easier to use
This commit is contained in:
@@ -20,13 +20,11 @@ LuaConsole::~LuaConsole() {
|
||||
void LuaConsole::clear() {
|
||||
raw_input_ = "";
|
||||
lines_ = 0;
|
||||
lua_expression_ = "";
|
||||
words_.clear();
|
||||
syntax_ = "";
|
||||
action_ = DO_NOTHING;
|
||||
prompt_ = "> ";
|
||||
}
|
||||
|
||||
|
||||
void LuaConsole::split_words() {
|
||||
words_.clear();
|
||||
std::string acc;
|
||||
@@ -64,7 +62,7 @@ void LuaConsole::add(std::string line) {
|
||||
split_words();
|
||||
if (words_.size() >= 1) {
|
||||
if (is_single_letter(words_[0]) || (util::validinteger(words_[0]))) {
|
||||
action_ = DO_COMMAND;
|
||||
// We have a valid parsed command. Return it.
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -89,19 +87,16 @@ void LuaConsole::add(std::string line) {
|
||||
size_t lmsg;
|
||||
const char *msg = lua_tolstring(lua_state_, -1, &lmsg);
|
||||
const char *tp = msg + lmsg - leof;
|
||||
if (strstr(msg, eof) == tp) {
|
||||
action_ = DO_NOTHING;
|
||||
} else {
|
||||
action_ = DO_SYNTAX;
|
||||
syntax_ = msg;
|
||||
if (strstr(msg, eof) != tp) {
|
||||
words_.push_back("syntax");
|
||||
words_.push_back(msg);
|
||||
}
|
||||
} else {
|
||||
action_ = DO_LUA;
|
||||
lua_expression_ = partial;
|
||||
words_.push_back("lua");
|
||||
words_.push_back(partial);
|
||||
}
|
||||
lua_settop(lua_state_, top);
|
||||
|
||||
if (action_ == DO_NOTHING) {
|
||||
if (words_.empty()) {
|
||||
prompt_ = ">> ";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user