diff --git a/Docs/README.add-ons b/Docs/README.add-ons index 847a58130..baabcfee3 100644 --- a/Docs/README.add-ons +++ b/Docs/README.add-ons @@ -41,9 +41,11 @@ add-on directory. Such a directory, when used as the argument of 4) The add-on directory must contain a Nasal file called main.nas. This file will be loaded at startup too, and its main() function run in the namespace __addon[ADDON_ID]__, where ADDON_ID is the - add-on identifier specified in the addon-metadata.xml file. This - operation is done by $FG_ROOT/Nasal/addons.nas at the time of this - writing. + add-on identifier specified in the addon-metadata.xml file. The + main() function is passed one argument: the addons.Addon object + (a Nasal ghost, see below) corresponding to the add-on being + loaded. This operation is done by $FG_ROOT/Nasal/addons.nas at the + time of this writing. Also, the Property Tree is populated (under /addons) with information about registered add-ons. More details will be given below. @@ -459,11 +461,11 @@ code easy access to add-on metadata, for instance like this: print(myAddon.version.str()); foreach (var author; myAddon.authors) { - print(author.name, author.email, author.url); + print(author.name, " ", author.email, " ", author.url); } foreach (var maintainer; myAddon.maintainers) { - print(maintainer.name, maintainer.email, maintainer.url); + print(maintainer.name, " ", maintainer.email, " ", maintainer.url); } print(myAddon.shortDescription); diff --git a/Nasal/addons.nas b/Nasal/addons.nas index 7f2a76cc7..8ad3a0bca 100644 --- a/Nasal/addons.nas +++ b/Nasal/addons.nas @@ -2,7 +2,8 @@ # 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]__ -# - call function main() from every such main.nas with the add-on path as arg. +# - call function main() from every such main.nas with the add-on ghost as +# argument (an addons.Addon instance). # Example: # @@ -14,7 +15,15 @@ # - 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]__ -# - this script calls main("/foo/bar/baz") from /foo/bar/baz/main.nas. +# - 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. # # For more details, see $FG_ROOT/Docs/README.add-ons. @@ -30,7 +39,7 @@ var id = _setlistener("/sim/signals/fdm-initialized", func { io.load_nasal( main_nas, namespace ); var addon_main = globals[namespace]["main"]; - var addon_main_args = [ addon.basePath ]; + var addon_main_args = [ addon ]; call(addon_main, addon_main_args); #, object, namespace, error_vector); # Tell the world that the add-on is now loaded.