Install

Loft is a lightweight scripting language with null safety, built-in parallel execution, and a fast interpreter called loft. This page shows how to install loft and write your first program.

Prerequisites

Building from source requires the Rust toolchain. loft is an edition-2024 crate, so that means Rust 1.96 or later — the same version --native needs to compile your programs. Install it from rustup.rs if you do not already have it:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install from source

Clone the repository and install it into ~/.local, with no root needed:

git clone https://github.com/loft-lang/loft
cd loft
make install-user

This puts the loft binary in ~/.local/bin/ and the standard library it loads at runtime in ~/.local/share/loft/, and tells you if ~/.local/bin is not on your PATH. make install installs system-wide under /usr/local instead.

Build locally

To run loft from the checkout without installing it:

cargo build --release
./target/release/loft --version

The binary at target/release/loft uses the standard library in the checkout's default/ directory, or share/loft/ beside an installed bin/. A copy with neither beside it still runs, on the standard library built into it. make install-user (or make install) is the way onto your PATH.

Verify the installation

loft --version

Hello, World

Create a file called hello.loft:

fn main() {
    println("Hello, Loft!");
}

Run it:

loft hello.loft
Hello, Loft!

A slightly bigger program

Variables, loops, and string interpolation all work without any ceremony:

fn main() {
    // Variables are mutable by default; types are inferred.
    total = 0;
    for n in 1..=10 {
        total += n;
    }
    println("Sum 1..10 = {total}");

    // Vectors use square-bracket literals.
    words = ["loft", "is", "fast"];
    for w in words {
        print("{w} ");
    }
    println("");
}

Command-line flags

Run loft --help for the full list. The most commonly used flags are:

FlagWhat it does
--helpShow all available options
--versionPrint the loft version
--path <dir>Look for the default/ standard library in dir instead of next to the binary
--interpretInterpret the program instead of compiling it — the other half of the choice loft makes for you
--timeout NStop the program after N seconds; worth using the first time you run something
--explainPrint the suggested fix under each diagnostic. It only shows the fix, so it is always safe to run
--nativeCompile to a native binary via rustc and run it (without Rust on PATH, loft says so and interprets)
--native-releaseSame as --native with full optimisations (slower to compile, fastest to run)
--native-emit [out.rs]Write the generated Rust source to a file without compiling it

Running your program as a native binary

loft myprogram.loft already compiles through rustc when it can find it, and interprets when it cannot — you do not have to choose, and the answer is the same either way. Compiling takes a few seconds the first time and then runs compute-heavy code many times faster than interpreting (Performance measures native against hand-written Rust). Ask for one on purpose when you want to:

loft --native myprogram.loft

To see the generated Rust code without running it:

loft --native-emit myprogram.rs myprogram.loft
cat myprogram.rs

Native runs need rustc on your PATH — the same Rust you built loft with. Without it, --native says so and interprets instead. A downloaded release carries no native runtime, so it always interprets.

Standard library

The standard library is a set of .loft files bundled alongside the loft binary. They are loaded automatically before your program runs — you do not need any import or use statement to call println, assert, or any other built-in function.

The full function reference is in the Standard Library section of these docs.

Using libraries

Place a library file (e.g. lib/myutil.loft) next to your program, then bring it into scope:

use myutil;

fn main() {
    result = myutil::compute(42);
    println("{result}");
}

See Libraries for the full search path and naming rules.

Editor setup

loft ships its own editor support, so you do not need to pretend .loft is Rust:

Next steps