import

import(file) — loads and executes another .scr file (extension optional).
It does two things:

  1. Merges the imported file’s globals into the root (current) global scope,
    so you can call its functions directly by name.
  2. Returns an object holding the imported globals, so you can also reach
    them namespaced through the return value (and tell them apart from any
    colliding names).
var math = import("libs/helper")
print(math.factorial(5))     # via the returned object
print(factorial(5))          # via the merged root global — same value

Every var/fn at the top level of the imported file is exported: the
import’s namespace object has one key per global, and that same name is bound
directly in the importing script’s root scope. const exports as const and
ref exports as an alias into the module’s storage; local names are erased
when the import finishes executing, so they never export.

# libs/helper.scr
fn factorial(n) {
  if (n <= 1) { return 1 }
  return n * factorial(n - 1)
}
var helper_name = "helper"
# main.scr
var h = import("libs/helper")
print(h.factorial(6))        # 720  (via object)
print(factorial(6))          # 720  (via root scope)
print(helper_name)           # helper  (imported global is available too)
print(keys(h))               # ["factorial", "helper_name"]

Importing is not scoped to the block where import appears — the globals
always land in the root scope. Beware collisions: an imported name that
overlaps an existing restricted global (such as a builtin like double or an
already-imported name) raises a REASSIGN_RESTRICTED error.

Imports resolve relative to the importing file (or via engine-configured
search paths).