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. Running a built loft needs no Rust at all — --native compiles through your system's C compiler. Install Rust 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 through C and your system's C compiler, and run it (without a C compiler on PATH, loft says so and interprets)
--shipBuilds the program as you ship it: fully optimised, with its native libraries linked in (slower to compile, fastest to run). Add --native-wasm, --html or --native-android to ship that target
--native-debugCompile with debug information naming your .loft source lines; combine with --ship for optimised + debug info
--native-emit [out.c]Write the generated C source to a file without compiling it

Running your program as a native binary

loft myprogram.loft already compiles through your system's C compiler when it can find one, and interprets when it cannot — you do not have to choose, and the answer is the same either way. Compiling needs no Rust toolchain at all: the C runtime is inside the loft binary. It takes under a second the first time, caches the binary, and runs compute-heavy code many times faster than interpreting (Performance measures native against hand-written Rust). Ask for it on purpose when you want to:

loft --native myprogram.loft

To see the generated C code without running it:

loft --native-emit myprogram.c myprogram.loft
cat myprogram.c

Target toolchains

What each compiled target needs on your machine:

targetneedsDebian / UbuntumacOSWindows
--nativea C compiler (cc, or the one LOFT_CC or CC names)apt install build-essentialxcode-select --installMinGW-w64 gcc
--native-wasmclang, lld, the WASI libc and the wasm32 compiler-rt (or the clang LOFT_WASM_CC names)apt install clang lld wasi-libc libclang-rt-dev-wasm32brew install llvm lld wasi-libc wasi-runtimes — found without settings; Apple's own clang has no wasm targetwasi-sdk (the x86_64-windows archive), with LOFT_WASM_CC=<wasi-sdk>/bin/clang.exe
--htmlthe wasm toolchain above, and binaryen's wasm-opt for a page that draws frames… and apt install binaryen… and brew install binaryen… and binaryen's bin on PATH

When a tool is missing, loft says which and what to install on the machine it runs on.

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