58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
//////////////////////////////////////////////////////
|
|
//
|
|
// LuaConsole:
|
|
//
|
|
// Used to parse lines of text that are being interactively typed
|
|
// in by a user.
|
|
//
|
|
// Whenever the user types in a line, you should add the line to
|
|
// the LuaConsole object. After adding a line, the console will
|
|
// recommend one of several actions:
|
|
//
|
|
// 1. DO_NOTHING: The input is not complete, so you need to wait.
|
|
// 2. DO_COMMAND: Execute a lua command.
|
|
// 3. DO_SYNTAX: Print a syntax error message.
|
|
// 4. DO_SLASH: Execute a slash-command that bypasses lua.
|
|
//
|
|
// Also: if the first character of the lua form is '=', then
|
|
// replace the '=' with 'return '.
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
|
|
#ifndef LUACONSOLE_HPP
|
|
#define LUACONSOLE_HPP
|
|
|
|
#include <string>
|
|
#include "luastack.hpp"
|
|
|
|
class LuaConsole {
|
|
public:
|
|
enum {
|
|
DO_NOTHING, // We need more input text.
|
|
DO_COMMAND, // We have a valid lua expression.
|
|
DO_SYNTAX, // We have a syntax error.
|
|
DO_SLASH, // We have a slash-command.
|
|
};
|
|
private:
|
|
lua_State *lua_state_;
|
|
int action_;
|
|
int lines_;
|
|
std::string expression_;
|
|
std::string syntax_;
|
|
|
|
public:
|
|
LuaConsole();
|
|
~LuaConsole();
|
|
|
|
int action() const { return action_; }
|
|
int lines() const { return lines_; }
|
|
const std::string &expression() const { return expression_; }
|
|
const std::string &syntax() const { return syntax_; }
|
|
|
|
void add(std::string line);
|
|
void add_stdin();
|
|
void clear();
|
|
};
|
|
|
|
#endif // LUACONSOLE_HPP
|