diff --git a/src/Scripting/scriptmgr.cxx b/src/Scripting/scriptmgr.cxx index 106cd032e..4d5f5029a 100644 --- a/src/Scripting/scriptmgr.cxx +++ b/src/Scripting/scriptmgr.cxx @@ -135,7 +135,7 @@ FGScriptMgr::update (double delta_time_sec) } bool -FGScriptMgr::run (const char * script) +FGScriptMgr::run (const char * script) const { #if defined(FG_PSL_STRING_COMPILE) // FIXME: detect and report errors @@ -151,5 +151,14 @@ FGScriptMgr::run (const char * script) #endif } +bool +FGScriptMgr::run_inline (const char * script) const +{ + string s = "int main () {\n"; + s += script; + s += "\n return 0;\n}\n"; + return run(s.c_str()); +} + // end of scriptmgr.cxx diff --git a/src/Scripting/scriptmgr.hxx b/src/Scripting/scriptmgr.hxx index 849449ee5..f52182488 100644 --- a/src/Scripting/scriptmgr.hxx +++ b/src/Scripting/scriptmgr.hxx @@ -65,12 +65,28 @@ public: * * Any included files are referenced relative to $FG_ROOT. This * is not very efficient right now, since it recompiles the script - * every time it runs. + * every time it runs. The script must have a main() function. * * @param script A string containing the script. * @return true if the script compiled properly, false otherwise. + * @see #run_inline */ - virtual bool run (const char * script); + virtual bool run (const char * script) const; + + + /** + * Run an inline in-memory user script. + * + * The script is executed as if it were surrounded by a main() + * function, so it cannot contain any top-level constructions like + * #include statements or function declarations. This is useful + * for quick one-liners. + * + * @param script A string containing the inline script. + * @return true if the script compiled properly, false otherwise. + * @see #run + */ + virtual bool run_inline (const char * script) const; };