Import
The import keyword is used to include definitions from other modules or files into the current file.
Syntax
Section titled “Syntax”[pub] import "module_path" [as alias];- The path must be a string literal.
- You can optionally use
asto give the imported module an alias. - If you didn’t specify an alias, the module’s public definitions will be available under its original name. eg.
import "utils/helpers"will make the definitions available ashelpersin the current file.
Example
Section titled “Example”import "utils/helpers.gluax" as helpers;// same asimport "utils/helpers" as helpers;// same asimport "utils/helpers";
func main() { helpers::do_something();}- All import statements must come before any other items in the file. You cannot place an import after a class, function, or any other item.
- The
.gluaxextension in the import path is optional. - You can use relative paths like
./or../in the import string. - Import paths must resolve to files within your workspace/project directory. Attempting to import files outside the project directory will result in an error.
- Using
asallows you to avoid naming conflicts.