allow lua console to handle expressions
Implemented using ilua, and "experimental compilation" technique.
This commit is contained in:
parent
db7643c253
commit
4a2eb88607
3 changed files with 23 additions and 1 deletions
|
@ -312,8 +312,9 @@ public:
|
|||
bool tlua_interpreter::lua_model::execute (const std::string & cmd)
|
||||
{
|
||||
LOG_LUA << "tlua_interpreter::model::execute...\n";
|
||||
|
||||
try {
|
||||
L_.throwing_run(cmd.c_str());
|
||||
L_.interactive_run(cmd.c_str());
|
||||
return true;
|
||||
} catch (game::lua_error & e) {
|
||||
add_dialog_message(std::string(e.what()));
|
||||
|
|
|
@ -476,7 +476,25 @@ void lua_kernel_base::run(const char * prog) {
|
|||
}
|
||||
}
|
||||
|
||||
// Tests if a program resolves to an expression, and pretty prints it if it is, otherwise it runs it normally. Throws exceptions.
|
||||
void lua_kernel_base::interactive_run(char const * prog) {
|
||||
std::string experiment = "_pretty_print(";
|
||||
experiment += prog;
|
||||
experiment += ")";
|
||||
|
||||
error_handler eh = boost::bind(&lua_kernel_base::throw_exception, this, _1, _2 );
|
||||
|
||||
try {
|
||||
// Try to load the experiment without syntax errors
|
||||
load_string(experiment.c_str(), eh);
|
||||
} catch (game::lua_error & e) {
|
||||
throwing_run(prog); // Since it failed, fall back to the usual throwing_run, on the original input.
|
||||
return;
|
||||
}
|
||||
// experiment succeeded, now run but log normally.
|
||||
cmd_log_ << "$ " << prog << "\n";
|
||||
protected_call(0, 0, eh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the "package" package into the Lua environment.
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
/** Runs a plain script, but reports errors by throwing lua_error.*/
|
||||
void throwing_run(char const * prog);
|
||||
|
||||
/** Tests if a program resolves to an expression, and pretty prints it if it is, otherwise it runs it normally. Throws exceptions.*/
|
||||
void interactive_run(char const * prog);
|
||||
|
||||
void load_package();
|
||||
|
||||
std::vector<std::string> get_global_var_names();
|
||||
|
|
Loading…
Add table
Reference in a new issue