Import
Import(file) loads and executes another .scr file (extension optional)
on the same state as the importing context — the module reads every
global you can read at that point.
Helper File
# libs/helper.scr
fn factorial(n) {
if (n <= 1) { return 1 }
return n * factorial(n - 1)
}
var helper_name = "helper"
Namespaced: var m = import(file)
The module’s top-level var/const declarations land in m
# main.scr
var h = import("libs/helper")
print(h.factorial(6)) # 720
print(keys(h)) # ["factorial", "helper_name"]
Bare: import(file) as a statement
The module’s statements run in the current scope.
# main.scr
import("libs/helper")
print(factorial(6)) # 720 — helper's names are globals now
print(helper_name) # helper
Order matters: an import runs like a script, at the point it appears. A
module sees the globals that exist when it runs — an earlier import’s
names are visible to a later one, and not the other way around.
Each file loads once
Importing a file twice anywhere — bare or namespaced — fails with
IMPORT_ALREADY_LOADED instead of silently reusing a cached copy
or re-running side effects. If you need a module’s names twice, load
into an global object to reuse.
Related failure modes:
- Circular imports raise
Import cycle detected: <file>— including
cycles through execution (a imports b, b’s execution imports a). - Chained imports are capped at a depth of 64.
Path resolution
Imports resolve against the process working directory and any
engine-configured search paths — not relative to the importing file.