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 (Rust 1.82 or later). 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

The quickest way to get the loft binary on your PATH:

cargo install --git https://github.com/jjstwerff/loft --bin loft

This compiles loft in release mode and places the binary in ~/.cargo/bin/, which is already on your PATH if you used rustup.

Build locally

Clone the repository and build with Cargo:

git clone https://github.com/jjstwerff/loft
cd loft
cargo build --release

The binary is at target/release/loft. Copy it anywhere on your PATH, for example:

cp target/release/loft ~/.local/bin/

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
--native [out]Compile to a native binary via rustc and run it (requires Rust on PATH)
--native-release [out]Same 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

The interpreter runs programs immediately, but for compute-heavy work you can compile to a native binary instead. This takes a few seconds the first time (it calls rustc in the background) but runs 10–50× faster:

loft --native myprogram.loft

To see the generated Rust code without running it:

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

Native compilation requires Rust 1.85 or later on your PATH. If rustc is not found, loft prints a clear error message telling you how to install it.

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 syntax highlighting extensions are planned. In the meantime:

Next steps