#Module [v2.1-alpha.11+]

Starts a new module or reopens an existing module.

#Module ModuleName

Parameters

ModuleName

A unique name for use with #Import.

[v2.1-alpha.21+]: This must be a valid identifier. Each module imported from file has its own set of module names, separate to the main script.

Remarks

The new module starts with an empty global namespace and implicit import from the built-in module.

[v2.1-alpha.21+]: The module ends at the next #Module directive in the current file, or at the end of the current file.

[v2.1-alpha.21+]: The #Module directive creates a subordinate module or sub-module, linked with either the main script file or a file imported by #Import. Modules linked with the same file can import each other by ModuleName, while other modules can import sub-modules by using a path-qualified name of the form "Path:ModuleName". The name __Init can be used to import the initial module of a group.

Modules defined this way take precedence over modules in the file system, but only for the exact ModuleName used in the directive.

[v2.1-alpha.20+]: If ModuleName is AHK, __Main or a name used with a previous #Module directive, the existing module is "reopened", allowing startup code and definitions to be added.

[v2.1-alpha.21+] The use of #Module in a file which is loaded multiple times via #Include is prohibited. This is because the module would be "reopened" and its content duplicated, often resulting in misleading messages about duplicate declarations. Note that this restriction does not apply to multiple instances of #Include in the same module, as in such cases the file is included only once.

#Module cannot be used within a block or as the body of a control flow statement.

Modules, Export, #Import, #Include