2017-07-18 10:14:50 +00:00
|
|
|
##
|
2017-12-02 22:33:18 +00:00
|
|
|
# Initialize addons configured with --addon=foobar command line switch:
|
|
|
|
# - get the list of registered add-ons
|
|
|
|
# - load the main.nas file of each add-on into namespace __addon[ADDON_ID]__
|
2018-01-08 08:49:27 +00:00
|
|
|
# - call function main() from every such main.nas with the add-on ghost as
|
|
|
|
# argument (an addons.Addon instance).
|
2017-07-18 10:14:50 +00:00
|
|
|
|
2017-12-02 22:33:18 +00:00
|
|
|
# Example:
|
|
|
|
#
|
2017-07-18 10:14:50 +00:00
|
|
|
# fgfs --addon=/foo/bar/baz
|
2017-12-02 22:33:18 +00:00
|
|
|
#
|
|
|
|
# - AddonManager.cxx parses /foo/bar/baz/addon-metadata.xml
|
|
|
|
# - AddonManager.cxx creates prop nodes under /addons containing add-on metadata
|
|
|
|
# - AddonManager.cxx loads /foo/bar/baz/config.xml into the Property Tree
|
|
|
|
# - AddonManager.cxx adds /foo/bar/baz to the list of aircraft paths (to get
|
|
|
|
# permissions to read files from there)
|
|
|
|
# - this script loads /foo/bar/baz/main.nas into namespace __addon[ADDON_ID]__
|
2018-01-08 08:49:27 +00:00
|
|
|
# - this script calls main(addonGhost) from /foo/bar/baz/main.nas.
|
|
|
|
# - the add-on ghost can be used to retrieve most of the add-on metadata, for
|
|
|
|
# instance:
|
|
|
|
# addonGhost.id the add-on identifier
|
|
|
|
# addonGhost.name the add-on name
|
|
|
|
# addonGhost.version.str() the add-on version as a string
|
|
|
|
# addonGhost.basePath the add-on base path (realpath() of
|
|
|
|
# "/foo/bar/baz" here)
|
|
|
|
# etc.
|
2017-12-02 22:33:18 +00:00
|
|
|
#
|
|
|
|
# For more details, see $FG_ROOT/Docs/README.add-ons.
|
2017-07-18 10:14:50 +00:00
|
|
|
|
2017-12-02 22:33:18 +00:00
|
|
|
var id = _setlistener("/sim/signals/fdm-initialized", func {
|
|
|
|
removelistener(id);
|
|
|
|
|
|
|
|
foreach (var addon; addons.registeredAddons()) {
|
|
|
|
var main_nas = addon.basePath ~ "/main.nas";
|
|
|
|
var namespace = "__addon" ~ "[" ~ addon.id ~ "]__";
|
|
|
|
logprint(5, "Initializing addon '" ~ addon.name ~
|
|
|
|
"' version " ~ addon.version.str() ~ " from " ~ main_nas ~
|
|
|
|
" in " ~ namespace);
|
2017-07-18 10:14:50 +00:00
|
|
|
io.load_nasal( main_nas, namespace );
|
2017-12-02 22:33:18 +00:00
|
|
|
|
2017-07-18 10:14:50 +00:00
|
|
|
var addon_main = globals[namespace]["main"];
|
2018-01-08 08:49:27 +00:00
|
|
|
var addon_main_args = [ addon ];
|
2017-07-18 10:14:50 +00:00
|
|
|
call(addon_main, addon_main_args); #, object, namespace, error_vector);
|
2017-12-02 22:33:18 +00:00
|
|
|
|
|
|
|
# Tell the world that the add-on is now loaded.
|
|
|
|
addon.node.getChild("loaded", 0, 1).setBoolValue(1);
|
2017-07-18 10:14:50 +00:00
|
|
|
}
|
|
|
|
})
|