Progress on mingw driver

This commit is contained in:
2021-10-07 14:58:20 -04:00
parent bce756d1fd
commit e7f55a2411
16 changed files with 405 additions and 172 deletions

View File

@@ -2,7 +2,7 @@
#include <string.h>
#include "luaconsole.hpp"
#include "util.hpp"
#include <iostream>
static bool is_single_letter(const std::string &s) {
return ((s.size() == 1) && (s[0] >= 'a') && (s[0] <= 'z'));
@@ -24,13 +24,14 @@ void LuaConsole::clear() {
words_.clear();
syntax_ = "";
action_ = DO_NOTHING;
prompt_ = "> ";
}
void LuaConsole::split_words() {
words_.clear();
std::string acc;
for (char c : raw_input_) {
if ((c == ' ')||(c == '\n')) {
if ((c == ' ')||(c == '\n')||(c == '\r')) {
if (!acc.empty()) {
words_.push_back(acc);
acc = "";
@@ -44,10 +45,13 @@ void LuaConsole::split_words() {
}
}
std::string LuaConsole::get_prompt() {
std::string result = prompt_;
prompt_ = "";
return result;
}
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] = ' ';
}
@@ -96,20 +100,9 @@ void LuaConsole::add(std::string line) {
lua_expression_ = partial;
}
lua_settop(lua_state_, top);
if (action_ == DO_NOTHING) {
prompt_ = ">> ";
}
}
void LuaConsole::add_stdin() {
if (action_ != DO_NOTHING) {
clear();
}
const int MAXINPUT = 1000;
char buf[MAXINPUT];
fputs(raw_input_.empty() ? "> " : ">> ", stdout);
fflush(stdout);
if (fgets(buf, MAXINPUT, stdin)) {
size_t len = strlen(buf);
if (len > 0 && buf[len - 1] == '\n')
buf[len - 1] = '\0';
add(buf);
}
}