DriftScript
Documentation

Guide

Modules and imports

A .drs file importing another, and a record extending another.

A .drs file can import another .drs file, and a record can extend another. A relative specifier is a file; anything else is a capability.

Two kinds of import, one spelling

The specifier decides. `"./door.drs"` is a file in your project. `"std/math"` and `"drift/scene"` are capabilities, and which of those two is which is the subject of the next chapter.

// The two prefixes, in one file.
//
// `std/math` is the language's own and is pure, so it links in any host. `drift/scene` is this
// engine's, and it carries the effect of reaching a scene. The prefix in the import is what tells
// you which of the two you are looking at.
//
// `Node` is not a language type either. It arrives with the capability, from whatever the host's
// scene is made of, which is why a consumer with no renderer still has a language.

import { clamp } from "std/math"
import { setRotation } from "drift/scene"

data Spin {
    speed: f32 = 45deg
}

fn turn(spin: Spin, node: Node, dt: f32) {
    let step = math.clamp(spin.speed * dt, 0, 90deg)
    scene.setRotation(node, 0, 1, 0, step)
}
One file, both kinds of capability import.

Records extend records

A data record may extend another, inheriting its fields base-most first, and standing in for it wherever it is expected. Module cycles are allowed; inheritance cycles are refused.

A dependent recompiles when an interface moves

Each compiled module carries an interface hash, so editing a function body does not invalidate everything that imports the file. That is what makes a large project's hot reload fast rather than technically present.