Modify luaconsole to use slash-command syntax

This commit is contained in:
2021-11-04 14:58:38 -04:00
parent 7966707450
commit bc01bd8513
2 changed files with 17 additions and 24 deletions

View File

@@ -4,10 +4,6 @@
#include "util.hpp"
#include <iostream>
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'