From 4e6f9e623985d8be8301f03c648a756d23c402af Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 9 Mar 2022 16:47:12 +0000 Subject: [PATCH] Nasal startup: allow more control over loading Allow excluding scripts entirely based on the startup load properties. --- src/Scripting/NasalSys.cxx | 16 +++++++++++++--- src/Scripting/NasalSys.hxx | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 734f9c9a1..4f8f28f90 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -1152,7 +1152,12 @@ void FGNasalSys::init() // Now load the various source files in the Nasal directory simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal")); - loadScriptDirectory(nasalDir, globals->get_props()->getNode("/sim/nasal-load-priority")); + + // load core Nasal scripts. In GUI startup mode, we restrict to a limited + // set of modules deliberately + loadScriptDirectory(nasalDir, + globals->get_props()->getNode("/sim/nasal-load-priority"), + fgGetBool("/sim/gui/startup")); // Add modules in Nasal subdirectories to property tree simgear::PathList directories = nasalDir.children(simgear::Dir::TYPE_DIR+ @@ -1298,7 +1303,8 @@ bool pathSortPredicate(const SGPath& p1, const SGPath& p2) // Loads all scripts in given directory, with an optional partial ordering of // files defined in loadorder. -void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir, SGPropertyNode* loadorder) +void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir, SGPropertyNode* loadorder, + bool excludeUnspecifiedInLoadOrder) { simgear::PathList scripts = nasalDir.children(simgear::Dir::TYPE_FILE, ".nas"); @@ -1319,6 +1325,10 @@ void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir, SGPropertyNode* load std::for_each(files.begin(), files.end(), loadAndErase); } + if (excludeUnspecifiedInLoadOrder) { + return; + } + // Load any remaining scripts. // Note: simgear::Dir already reports file entries in a deterministic order, // so a fixed loading sequence is guaranteed (same for every user) @@ -1538,7 +1548,7 @@ bool FGNasalSys::createModule(const char* moduleName, const char* fileName, void FGNasalSys::deleteModule(const char* moduleName) { - if (!_inited) { + if (!_inited || naIsNil(_globals)) { // can occur on shutdown due to us being shutdown first, but other // subsystems having Nasal objects. return; diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 7868882e9..c36ced3e3 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -168,7 +168,8 @@ private: void loadPropertyScripts(); void loadPropertyScripts(SGPropertyNode* n); - void loadScriptDirectory(simgear::Dir nasalDir, SGPropertyNode* loadorder); + void loadScriptDirectory(simgear::Dir nasalDir, SGPropertyNode* loadorder, + bool excludeUnspecifiedInLoadOrder); void addModule(std::string moduleName, simgear::PathList scripts); static void logError(naContext); naRef parse(naContext ctx, const char* filename, const char* buf, int len,