Makeclass cleaned up

This commit is contained in:
2021-02-10 16:22:24 -05:00
parent e838b4ac97
commit 3883f86dee
13 changed files with 120 additions and 54 deletions

View File

@@ -1,6 +1,12 @@
#include <string.h>
#include "luaconsole.hpp"
#include "util.hpp"
static bool is_single_letter(const std::string &s) {
return ((s.size() == 1) && (s[0] >= 'a') && (s[0] <= 'z'));
}
LuaConsole::LuaConsole() {
lua_state_ = lua_open();
@@ -52,14 +58,16 @@ void LuaConsole::add(std::string line) {
// Try to interpret it as a special command.
if (lines_ == 1) {
split_words();
if ((words_.size() >= 1)&&(words_[0].size() == 1)) {
action_ = DO_COMMAND;
return;
if (words_.size() >= 1) {
if (is_single_letter(words_[0]) || (util::validinteger(words_[0]))) {
action_ = DO_COMMAND;
return;
}
}
}
words_.clear();
// Strip the leading punctuation from lua commands.
// Translate lua expression with leading '=' to 'return'
std::string partial;
if (raw_input_[0] == '=') {
partial = std::string("return ") + raw_input_.substr(1);
@@ -67,7 +75,7 @@ void LuaConsole::add(std::string line) {
partial = raw_input_;
}
// Analyze lua expressions.
// Try to parse the lua expression
int top = lua_gettop(lua_state_);
int status = luaL_loadbuffer(lua_state_, partial.c_str(), partial.size(), "=stdin");
if (status == LUA_ERRSYNTAX)