Skip to content

08 Namespaces

PlayeRom edited this page Nov 17, 2025 · 1 revision

The namespace into which the add-on's additional Nasal files will be loaded it will be a namespace created by FlightGear, in the format __addon[your-addon-id]__, where your-addon-id is the ID of your add-on specified in the /addon-metadata.xml file in <identifier> tag. To access this namespace from globals namespace, you need to refer to it as follows: globals[‘__addon[your-addon-id]__’], what will be needed, for example, to execute your code from the menu item (/addon-menubar-items.xml file). This is an inconvenient and long name to use, so if you want, you can create a global alias for it. This namespace alias can be passed as the second argument to the Application.create() function, e.g.:

Application.create(addon, 'yourAddon');

Here, of course, change the name yourAddon to something that reflects your add-on and is unique to the entire FlightGear project. Now, in the /addon-menubar-items.xml file, you can refer to the add-on variables like this: yourAddon.g_AboutDialog.show();, which greatly simplifies the code.

So the framework loads Nasal files into __addon[your-addon-id]__, which means it does not create additional namespaces, keeping everything in one place.

However, Canvas widgets are (and must be) loaded into the canvas namespace. This is the namespace used by FlightGear. It's important that your widget names don't conflict with other names used in this namespace, including those loaded from other add-ons. Therefore, if you're migrating a widget from another add-on or FlightGear to your project, rename it in the code to a unique name (both the view and the model).

The Framework autoloader will automatically load widget files into the canvas namespace, provided that your widgets are located in the Widgets subdirectory, which will be somewhere in the /nasal directory. The suggested directory is /nasal/Canvas/Widgets/.

Clone this wiki locally