Modules¶
Importing a file¶
Use import to run another .luz file. Everything defined in that file (variables, functions, classes) becomes available in the global scope:
Path resolution¶
The path in import is relative to the file that contains the import statement.
Execution model¶
When a file is imported:
- The file is read and executed from top to bottom.
- All definitions land in the global scope of the importing file.
- The import happens at the point where the
importstatement appears.
Circular imports¶
Luz automatically tracks which files have been imported. If a file tries to import a file that is already being executed (directly or transitively), the second import is silently skipped.
Example¶
greetings.luz:
function hello(name) {
return $"Hello, {name}!"
}
function goodbye(name) {
return $"Goodbye, {name}!"
}
main.luz: