Nasal Initialization: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(initial version)
 
mNo edit summary
Line 5: Line 5:


== Root directory / core modules ==
== Root directory / core modules ==
The nasal root folder (FGDATA/Nasal/) is scanned for .nas files.
The nasal root folder (FGDATA/Nasal/) is scanned for .nas files and these files are loaded (apparantly in alphabetical order).
This files are loaded (apparantly in alphabetical order).
After all .nas files are loaded <nowiki>sim/signals/nasal-dir-initialized</nowiki> is set, which triggers listeners in some of the files just loaded.
After all .nas files are loaded <nowiki>sim/signals/nasal-dir-initialized</nowiki> is set which triggers listeners in some of the files just loaded.
This allows to use functions from other core files, which have just been defined, e.g. which were not yet available when parsing the file.
This allows to use functions, which have been just defined in the core modules, e.g. which were not available when parsing the files.


== Sub-directories ==
== Sub-directories ==
After the files in the root directory have been processed, the first level of subdirectories is scanned for .nas files.
After the files in the root directory have been processed, the first level of subdirectories is scanned for .nas files.
Each subdirectory defines a module / namespace which becomes available only after the files in the subdirectory have been completly parsed,  
Each subdirectory defines a module / namespace which becomes available only after the files in the subdirectory have been completly processed,  
e.g. a variable foo in module bar becomes available as bar.foo only after parsing of the respective folder.
e.g. a variable foo in module bar becomes available as bar.foo only after parsing of the respective folder.


Sub-sub-directories will not be scanned for .nas files - at least not automatically on FG startup.
'''Sub-sub-directories will not be scanned for .nas files - at least not automatically on FG startup.'''
Of course, files of sub-sub-directories can be included (sooner or later) by the Nasal code that ''is'' being processed, so optional code can be loaded on demand.


= Open questions =
= Open questions =
Review the sources to confirm / update this doc.
Review the sources to confirm / update this doc.

Revision as of 10:09, 7 January 2020

some notes on how Nasal files from FGDATA/Nasal appear to be processed when Flightgear is started.

Initialization of Nasal core-/default-modules

When Flightgear starts, it will start the Nasal parser and load modules from FGDATA/Nasal.

Root directory / core modules

The nasal root folder (FGDATA/Nasal/) is scanned for .nas files and these files are loaded (apparantly in alphabetical order). After all .nas files are loaded sim/signals/nasal-dir-initialized is set, which triggers listeners in some of the files just loaded. This allows to use functions from other core files, which have just been defined, e.g. which were not yet available when parsing the file.

Sub-directories

After the files in the root directory have been processed, the first level of subdirectories is scanned for .nas files. Each subdirectory defines a module / namespace which becomes available only after the files in the subdirectory have been completly processed, e.g. a variable foo in module bar becomes available as bar.foo only after parsing of the respective folder.

Sub-sub-directories will not be scanned for .nas files - at least not automatically on FG startup. Of course, files of sub-sub-directories can be included (sooner or later) by the Nasal code that is being processed, so optional code can be loaded on demand.

Open questions

Review the sources to confirm / update this doc.