#Import [v2.1-alpha.20+]

Imports a module and optionally imports names from a module.

#Import Export ModuleName as ModuleAlias { *, ExportName ... }

Parameters

ModuleName

A module name, path or resource specifier. It must be either a valid identifier or a literal string, but either syntax can be used when importing a module defined by #Module or a file.

Paths can be absolute or relative to any of the search directories.

To load an embedded script as a module, specify an asterisk followed by the resource name. For example: "*RESNAME".

[v2.1-alpha.21+]: To import a sub-module from a different group, use a path-qualified name of the form "Path:ModuleName". Path should identify the main module of the group, which is either the script itself or a file imported by #Import.

ModuleAlias

An identifier to use within the current module to refer to the imported module's default export.

ExportName

An identifier which is exported from the module.

[v2.1-alpha.21+]: This can be the name of any function, class or global variable, including the module's own aliases of names it has imported.

Alias

An identifier to use within the current module in place of ExportName.

Import from File

Imports are processed after the main script file has been parsed, in an unspecified order. If ModuleName (excluding quote marks) does not match a module defined by #Module or previously imported from file, #Import attempts to locate a module file and load it. For details, see Search Path.

Imported Names

The module's default export (typically the module itself) is added to the current module's global namespace only if ModuleAlias is specified or ModuleName is unquoted.

If * is used, each unassigned and undeclared name in the current module may implicitly resolve to a name exported from ModuleName by an Export declaration. If a name is exported from multiple imported modules, the last import takes precedence. Explicit imports and other declarations take precedence over implicit imports, regardless of order.

Note: An implicitly imported variable cannot be the target of an assignment, as the presence of an assignment would cause a new variable to be created in the current module.

A load-time error is raised if any name used in an explicit import is also used in some other declaration within the current module.

Export

If the export keyword is used, all explicitly imported names are also exported from the current module.

[v2.1-alpha.24+]: Export can also be used with wildcard import.

Remarks

Line breaks can be used inside the braces, due to continuation by enclosure.

Classes and functions are available even before the source module has executed, such as if the module which imports them is executing first due to a circular import.

Modules, Export, #Module, #Include