]> git.mxchange.org Git - flightgear.git/commitdiff
Added a run_inline method that automatically wraps the script in a
authordavid <david>
Thu, 16 Jan 2003 18:04:24 +0000 (18:04 +0000)
committerdavid <david>
Thu, 16 Jan 2003 18:04:24 +0000 (18:04 +0000)
main() function.  It's not hooked to a command, yet.

src/Scripting/scriptmgr.cxx
src/Scripting/scriptmgr.hxx

index 106cd032ead962abf01835dacf65750ab8b170a1..4d5f5029ab3f521c5f5a09e8c27d578847253fb6 100644 (file)
@@ -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
index 849449ee55edd9c3458cfa1c5a867480a0d09b9c..f521824882fa0d4d54b53d502204621309fb758c 100644 (file)
@@ -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;
     
 };