250
edits
(4 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
== Core modules == | == Core modules == | ||
The nasal root folder (FGDATA/Nasal/) is scanned for .nas files and these files are loaded (apparantly in alphabetical order). | 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 | After all .nas files are loaded {{code|/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. | 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. | ||
{{note|for a list of modules see [[Nasal Modules]]|margin=10px|width=50%}} | |||
== Optional load-once modules == | == Optional (load-once) modules == | ||
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 processed, | Each subdirectory defines a module / namespace which becomes available only after the files in the subdirectory have been completly processed, | ||
Line 21: | Line 22: | ||
=== Enabling of load-once modules === | === Enabling of load-once modules === | ||
From the user (aircraft developer) point of view, enabling of this modules is done by setting the property {{code|/nasal/<moduleName>/enabled}} to {{code|true}}. | |||
If a module is needed by an aircraft, you can just add the following to your aircraft-set.xml file (replace ''module_name'' by the name of the desired module): | |||
<syntaxhighlight lang="xml"> | |||
<PropertyList> | |||
<nasal> | |||
<module_name> | |||
<enabled type="bool">true</enabled> | |||
</module_name> | |||
<nasal> | |||
</PropertyList> | |||
</syntaxhighlight> | |||
Loading is done in the C++ code and is a little bit complicated (see FG sources /src/Scripting/NasalSys.cxx). | |||
''FGNasalSys::init()'' scans FGDATA/Nasal for subdirectories and calls ''FGNasalSys::addModule()'' for each subdirectory passing its name as module name and a list of all .nas files in it. | ''FGNasalSys::init()'' scans FGDATA/Nasal for subdirectories and calls ''FGNasalSys::addModule()'' for each subdirectory passing its name as module name and a list of all .nas files in it. | ||
Line 37: | Line 50: | ||
If the namespace already exists, the module will be added to it so you can extend existing modules. But be very careful when overloading existing modules, you can easily break things.}} | If the namespace already exists, the module will be added to it so you can extend existing modules. But be very careful when overloading existing modules, you can easily break things.}} | ||
= Re-loadable modules = | == Re-loadable modules == | ||
This type of module can be loaded and unloaded at runtime without exiting or restarting FlightGear. | |||
See [[Modules.nas]] for details. |
edits