Modify luaconsole to use slash-command syntax
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -10,19 +10,21 @@
|
||||
// 3. Add the line to the LuaConsole using 'add'.
|
||||
// 4. Get the command words using 'get_command'.
|
||||
// 5. If the command is empty, do nothing.
|
||||
// 6. If the command is nonempty, execute it and call 'clear'.
|
||||
// 6. If the command is nonempty, execute it.
|
||||
//
|
||||
// The 'words' returned by the luaconsole can be empty, meaning
|
||||
// that there's no command to execute. If the words are nonempty,
|
||||
// then the first word is the command. There are two hardwired
|
||||
// commands:
|
||||
// The LuaConsole expects you to type one of three things:
|
||||
//
|
||||
// lua <expr> - execute a lua expression
|
||||
// syntax <message> - print a syntax error message
|
||||
// * Valid Lua Code.
|
||||
// * Valid Lua Code preceded by '=' as shorthand for 'return'
|
||||
// * A slash-command.
|
||||
//
|
||||
// If the first word is anything else, it means the user typed
|
||||
// that word on the command line. It is up to you to interpret
|
||||
// such commands.
|
||||
// The 'get_command' returned by the luaconsole can be one of
|
||||
// the following:
|
||||
//
|
||||
// empty vector - still collecting input: do nothing.
|
||||
// lua <expr> - found a lua command: execute it as lua.
|
||||
// syntax <words> - detected a syntax error: print the error.
|
||||
// word word ... - read a slash-command: execute the command.
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user