Attach / Modules
Astra lets you split your code across multiple .astra files and load them with attach. Functions defined in the attached file become available in your program instantly — no build steps, no exports.
| Syntax | What it does |
|---|---|
| attach "file.astra" | Load file, functions available directly by name |
| attach "file.astra" as x | Load file, functions available as x.fnName() |
Basic attach
Use attach "filename.astra" to load another file. All functions defined in that file can be called directly — no prefix needed.
💡 All functions from the attached file are available directly — call
add(), mul() without any prefix.attach as — Alias
If two files define the same function name, they will conflict. Use attach "file.astra" as name to give a file a namespace — then call its functions as name.function().
⚠️ If two files define the same function name, an alias is required — otherwise there will be a conflict.
Multiple Modules
You can attach as many files as you need — with or without an alias.
Writing a Module
Just define functions in any .astrafile — that's it, it's a module. No special syntax, no exports needed.
Example — strings.astra
Example — math utils
Common Patterns
Shared constants file
Split by feature
ℹ️ Attached files can themselves use
attach — nested modules are supported. File paths are resolved relative to the location of the .astra file.