Initializing Nasal early: Difference between revisions

Jump to navigation Jump to search
m
http://forum.flightgear.org/viewtopic.php?f=30&t=21083&p=214428#p214428
No edit summary
m (http://forum.flightgear.org/viewtopic.php?f=30&t=21083&p=214428#p214428)
Line 69: Line 69:
}}
}}


{{FGCquote
  |for FGCanvas-testing, I just used a slightly-extended version of this:
<syntaxhighlight lang="diff">
diff --git a/src/Main/options.cxx b/src/Main/options.cxx
index 0389faa..f23a7ec 100644
--- a/src/Main/options.cxx
+++ b/src/Main/options.cxx
@@ -1434,8 +1434,9 @@ struct OptionDesc {
    int (*func)( const char * );
    } fgOptionArray[] = {
+    {"boot-script",          true,  OPTION_STRING, "/sim/startup/boot-script", false, "default.boot", 0 },
    {"language",                    true,  OPTION_IGNORE, "", false, "", 0 },
-  {"console",                      false, OPTION_IGNORE,  "", false, "", 0 },
+    {"console",                      false, OPTION_IGNORE,  "", false, "", 0 },
    {"disable-rembrandt",            false, OPTION_BOOL,  "/sim/rendering/rembrandt/enabled", false, "", 0 },
    {"enable-rembrandt",            false, OPTION_BOOL,  "/sim/rendering/rembrandt/enabled", true, "", 0 },
    {"renderer",                    true,  OPTION_STRING, "/sim/rendering/rembrandt/renderer", false, "", 0 },
diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx
index fde6319..c96ca90 100644
--- a/src/Scripting/NasalSys.cxx
+++ b/src/Scripting/NasalSys.cxx
@@ -833,6 +833,7 @@ void FGNasalSys::init()
      .member("singleShot", &TimerObj::isSingleShot, &TimerObj::setSingleShot)
      .member("isRunning", &TimerObj::isRunning);
+#if 0
    // Now load the various source files in the Nasal directory
    simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal"));
    loadScriptDirectory(nasalDir);
@@ -845,6 +846,18 @@ void FGNasalSys::init()
        simgear::PathList scripts = dir.children(simgear::Dir::TYPE_FILE, ".nas");
        addModule(directories[i].file(), scripts);
    }
+#endif
+
+    const char* boot_script = fgGetString("/sim/startup/boot-script", "default.boot");
+    SGPath fullpath(globals->get_fg_root(), "Boot");
+    fullpath.append(boot_script);
+
+    SG_LOG(SG_NASAL, SG_INFO, "Using boot script:" << fullpath);
+    SGPath file = fullpath.file();
+    if(!loadModule(fullpath, "boot")) {
+      SG_LOG(SG_NASAL, SG_ALERT, "Error could not load boot script:" << fullpath);
+    exit(-1);
+    }
    // set signal and remove node to avoid restoring at reinit
    const char *s = "nasal-dir-initialized";
</syntaxhighlight>
As you can see, the file name of the "boot script" defaults to $FG_ROOT/Boot/default.boot but can be easily overridden to add custom modes.<br/>
Which is kinda where we could now add your bootstrap.nas logic and review the necessary C++ changes to make it work.<br/>
For testing purposes, I used io.nas as the template for my own boot script, i.e. to load globals.nas, props.nas etc<br/>
<br/>
Once the hard-coded functionality is re-implemented, we can explore making things better configurable, i.e. more optional, over time.
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=214428#p214428
    |title=<nowiki>Re: Modular Nasal bootstrapping (again)</nowiki>
    |author=<nowiki>Hooray</nowiki>
    |date=<nowiki>Wed Jul 09</nowiki>
  }}
}}
<references/>
<references/>


For the sake of simplicity, we could refactor the ::init() method such that the common init code could be shared, between the initial startup Nasal interpreter, and the final runtime interpreter - so that we could load init code from a separate $FG_ROOT directory to do such things, without parsing all the stuff in $FG_ROOT/Nasal.
For the sake of simplicity, we could refactor the ::init() method such that the common init code could be shared, between the initial startup Nasal interpreter, and the final runtime interpreter - so that we could load init code from a separate $FG_ROOT directory to do such things, without parsing all the stuff in $FG_ROOT/Nasal.

Navigation menu