Minor improvements to LuaConsole.cpp
This commit is contained in:
@@ -12,13 +12,16 @@ LuaConsole::~LuaConsole() {
|
||||
}
|
||||
|
||||
void LuaConsole::clear() {
|
||||
expression_="";
|
||||
expression_ = "";
|
||||
lines_ = 0;
|
||||
syntax_="";
|
||||
state_=STATE_INCOMPLETE;
|
||||
syntax_ = "";
|
||||
action_ = DO_NOTHING;
|
||||
}
|
||||
|
||||
void LuaConsole::add(std::string line) {
|
||||
if (action_ != DO_NOTHING) {
|
||||
clear();
|
||||
}
|
||||
for (int i = 0; i < int(line.size()); i++) {
|
||||
if (line[i] == '\n') line[i] = ' ';
|
||||
}
|
||||
@@ -34,10 +37,10 @@ void LuaConsole::add(std::string line) {
|
||||
// Analyze slash-commands.
|
||||
if (expression_[0] == '/') {
|
||||
if (lines_ == 1) {
|
||||
state_ = STATE_SLASHCOMMAND;
|
||||
action_ = DO_SLASH;
|
||||
syntax_ = "";
|
||||
} else {
|
||||
state_ = STATE_SYNTAX;
|
||||
action_ = DO_SYNTAX;
|
||||
syntax_ = "slash command has more than one line";
|
||||
}
|
||||
return;
|
||||
@@ -54,19 +57,22 @@ void LuaConsole::add(std::string line) {
|
||||
const char *tp = msg + lmsg - (sizeof(eof) - 1);
|
||||
if (strstr(msg, eof) == tp) {
|
||||
syntax_ = "";
|
||||
state_ = STATE_INCOMPLETE;
|
||||
action_ = DO_NOTHING;
|
||||
} else {
|
||||
syntax_ = msg;
|
||||
state_ = STATE_SYNTAX;
|
||||
action_ = DO_SYNTAX;
|
||||
}
|
||||
} else {
|
||||
syntax_ = "";
|
||||
state_ = STATE_COMPLETE;
|
||||
action_ = DO_COMMAND;
|
||||
}
|
||||
lua_settop(lua_state_, top);
|
||||
}
|
||||
|
||||
void LuaConsole::add_stdin() {
|
||||
if (action_ != DO_NOTHING) {
|
||||
clear();
|
||||
}
|
||||
const int MAXINPUT = 1000;
|
||||
char buf[MAXINPUT];
|
||||
fputs(expression_.empty() ? "> " : ">> ", stdout);
|
||||
|
||||
Reference in New Issue
Block a user