1
0
Fork 0

Added a run_inline method that automatically wraps the script in a

main() function.  It's not hooked to a command, yet.
This commit is contained in:
david 2003-01-16 18:04:24 +00:00
parent 2256c3d5fd
commit af4f1894c9
2 changed files with 28 additions and 3 deletions

View file

@ -135,7 +135,7 @@ FGScriptMgr::update (double delta_time_sec)
} }
bool bool
FGScriptMgr::run (const char * script) FGScriptMgr::run (const char * script) const
{ {
#if defined(FG_PSL_STRING_COMPILE) #if defined(FG_PSL_STRING_COMPILE)
// FIXME: detect and report errors // FIXME: detect and report errors
@ -151,5 +151,14 @@ FGScriptMgr::run (const char * script)
#endif #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 // end of scriptmgr.cxx

View file

@ -65,12 +65,28 @@ public:
* *
* Any included files are referenced relative to $FG_ROOT. This * Any included files are referenced relative to $FG_ROOT. This
* is not very efficient right now, since it recompiles the script * 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. * @param script A string containing the script.
* @return true if the script compiled properly, false otherwise. * @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;
}; };