Implement probe_lua and add it to lpxclient/lpxserver

This commit is contained in:
2021-11-26 13:56:24 -05:00
parent c02109699e
commit 1e93533246
10 changed files with 134 additions and 35 deletions

View File

@@ -78,14 +78,6 @@ void LuaConsole::simplify(const StringVec &words) {
if (words.size() != 1) {
synerr("/quit takes no arguments");
}
} else if (words[0] == "snap") {
if (words.size() != 1) {
synerr("/snap takes no arguments");
}
} else if (words[0] == "roll") {
if (words.size() != 1) {
synerr("/roll takes no arguments");
}
} else if (words[0] == "tick") {
if ((words.size() == 2)&&(util::validinteger(words[1]))) {
// OK
@@ -120,11 +112,20 @@ void LuaConsole::add(std::string line) {
return;
}
// Translate lua expression with leading '=' to 'return'
// Translate lua expression, deal with initial prefix.
std::string partial;
if (raw_input_[0] == '=') {
std::string lua_mode;
if (util::has_prefix(raw_input_, "?=")) {
lua_mode = "luaprobe";
partial = std::string("return ") + raw_input_.substr(2);
} else if (util::has_prefix(raw_input_, "?")) {
lua_mode = "luaprobe";
partial = raw_input_.substr(1);
} else if (util::has_prefix(raw_input_, "=")) {
lua_mode = "luainvoke";
partial = std::string("return ") + raw_input_.substr(1);
} else {
lua_mode = "luainvoke";
partial = raw_input_;
}
@@ -144,7 +145,7 @@ void LuaConsole::add(std::string line) {
clear_raw_input();
}
} else {
words_.push_back("lua");
words_.push_back(lua_mode);
words_.push_back(util::rtrim(partial));
clear_raw_input();
}