Remove luaconsole.hpp - this has been dead code a long time

This commit is contained in:
2026-02-21 03:19:30 -05:00
parent 2170b9fdde
commit 0531f50056
2 changed files with 0 additions and 185 deletions

View File

@@ -1,108 +0,0 @@
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "eng-malloc.hpp"
#include "luastack.hpp"
#include "luaconsole.hpp"
#include "util.hpp"
#include <cstring>
#include <iostream>
LuaConsole::LuaConsole() {
clear_raw_input();
}
LuaConsole::~LuaConsole() {
}
static LuaConsole::StringVec split_words(const eng::string &raw) {
LuaConsole::StringVec result;
eng::string acc;
for (char c : raw) {
if ((c == ' ')||(c == '\n')||(c == '\r')) {
if (!acc.empty()) {
result.push_back(acc);
acc = "";
}
} else {
acc += c;
}
}
if (!acc.empty()) {
result.push_back(acc);
}
return result;
}
LuaConsole::StringVec LuaConsole::get_command() {
StringVec result = words_;
words_.clear();
return result;
}
void LuaConsole::clear_raw_input() {
raw_input_ = "";
lines_ = 0;
prompt_ = "> ";
}
void LuaConsole::add(eng::string line) {
for (int i = 0; i < int(line.size()); i++) {
if (line[i] == '\n') line[i] = ' ';
}
raw_input_ += line;
raw_input_ += '\n';
lines_ += 1;
prompt_ = ">> ";
words_.clear();
// Try to interpret it as a slash-command.
if ((lines_ == 1)&&(raw_input_[0] == '/')) {
words_ = split_words(raw_input_.substr(1));
if ((words_.size() == 1) && (sv::valid_int64(words_[0]))) {
eng::string num = words_[0];
words_.clear();
words_.push_back("choose");
words_.push_back(num);
}
clear_raw_input();
return;
}
// Translate lua expression, deal with initial prefix.
eng::string partial;
eng::string lua_mode;
if (sv::has_prefix(raw_input_, "?=")) {
lua_mode = "luaprobe";
partial = eng::string("return ") + raw_input_.substr(2);
} else if (sv::has_prefix(raw_input_, "?")) {
lua_mode = "luaprobe";
partial = raw_input_.substr(1);
} else if (sv::has_prefix(raw_input_, "=")) {
lua_mode = "luainvoke";
partial = eng::string("return ") + raw_input_.substr(1);
} else {
lua_mode = "luainvoke";
partial = raw_input_;
}
// Try to parse the lua expression
{
LuaVar result;
LuaExtStack LS(lua_state_, result);
eng::string errmsg = LS.load(result, partial, "stdin");
if (errmsg.empty()) {
words_.push_back(lua_mode);
words_.emplace_back(sv::rtrim(partial));
clear_raw_input();
} else if (errmsg.find("<eof>") != std::string::npos) {
// We have an incomplete expression.
// Do nothing, just let the user type more stuff.
} else {
words_.push_back("syntax");
words_.push_back(errmsg);
clear_raw_input();
}
}
}

View File

@@ -1,77 +0,0 @@
//////////////////////////////////////////////////////
//
// LuaConsole:
//
// Used to parse commands that are being interactively typed
// in by a user. The common usage pattern is:
//
// 1. Print the prompt suggested by 'get_prompt'.
// 2. Read a line of text from stdin.
// 3. Add the line to the LuaConsole using 'add'.
// 4. Get the command word using get_command.
// 5. If the command is empty, do nothing.
// 6. If the command is nonempty, get the args and execute it.
//
// The LuaConsole expects you to type a lua command, or one
// of the following slash-commands:
//
// /quit - exit the program
// /view - display the nearby tangibles
// /menu [tanid] - display the menu for tangible
// /tick [timevalue] - advance the simulation clock
// /choose [number] - choose menu item number
// /1234 - choose menu item 1234
//
// If you type anything else, the LuaConsole will generate a
// syntax error. Note that not all of the commands above are
// supported in all interpreters.
//
// Lua commands can be one of the following:
//
// <expression> - invoke "<expression>""
// = <expression> - invoke "return <expression>"
// ? <expression> - probe "<expression>"
// ?= <expression> - probe "return <expression>"
//
// Once a command has been typed (or a syntax error has been
// typed), the LuaConsole will return the command. The command
// can be fetched using command(), int_arg(), and str_arg()
//
//////////////////////////////////////////////////////
#ifndef LUACONSOLE_HPP
#define LUACONSOLE_HPP
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "luastack.hpp"
class LuaConsole {
private:
eng::string raw_input_;
int lines_;
eng::string prompt_;
void clear_raw_input();
public:
LuaConsole();
~LuaConsole();
// Fetch the recommended prompt.
//
// You should update the prompt immediately after 'add'.
//
const eng::string &get_prompt() { return prompt_; }
// Get the command words.
//
StringVec get_command();
// Add a line of text that was just read from the console.
//
void add(eng::string line);
};
#endif // LUACONSOLE_HPP