Documentation

Luma documentation

Luma is a small programming language with its own compiler. It’s designed to be easy to read and easy to understand completely.

Every Luma program can be run two ways:

  • Interpreted: luma run hello.luma runs the program straight away.
  • Compiled: luma build hello.luma produces a small native executable for Linux or Windows that runs on its own.

Both ways behave the same and print the same output.

name: str = "Luma"
version: int = 1

if version > 0 {
    print("Hello from")
    print(name)
}

Output:

Hello from
Luma

The language at a glance

FeatureExample
Comment// to the end of the line (no /* */)
Declare a variablecount: int = 0
Assigncount = count + 1
Typesint float byte bool str error file json [int] {str: int} {str}, and your own obj types
Interpolation"Hello ${name}, you are ${age + 1}"
Arithmetic+ - * / %
Comparison== != < <= > >=
Logic&& || !
Decisionif x > 0 { ... } else if x < 0 { ... } else { ... }
Listnums: [int] = [1, 2, 3]
List accessnums[0], nums[0] = 5, nums[] = 4 (append)
Mapages: {str: int} = {"Alice": 30}
Map accessages["Alice"], ages["Bob"] = 25, has(ages, "Bob")
Setnames: {str} = {"Alice", "Bob"}, names[] = "Carol" (add)
Loopnums.walk(n) { ... }, ages.walk(name, age) { ... }, skip, stop
Error handlingtry err { ... }, throw error(100, "message"), err.code, err.message
Inputname: str = prompt("Name: "), age: int = prompt("Age: ")
Flagsport: int = flag("port", 8080), then ./app --port=9000
Filesnotes: file = file("notes.txt"), notes.write(text), lines: [str] = notes.read(), notes.add(line)
Texts.upper(), s.trim(), s.split(","), s.replace(a, b), s.part(0, 3), words.join(" "), len(s)
JSONconfig: json = convert(text), port: int = convert(config["port"]), user: json = {"name": "Ann", "age": 30}
Conversionn: int = convert("42"), s: str = convert(n): the target type decides
Memoryautomatic; free(x) ends a variable early
Built-in functionsprint(x), prompt(text), flag(name, default), file(path), free(x), len(x), remove(x, i), has(x, k), error(code, msg)
Functionfn greet(name: str): str { return "Hi ${name}" }
Importsimport "lib/text", text.upper(s), (import "lib/text").upper(s), pub fn ...
Locked valuelock PI: float = 3.14 (fixed when compiling, usable in functions)
Objectsobj Point { x: int = 0 fn move(d: int) { self.x = self.x + d } }, p: Point = Point { x: 1 }, p.move(2)
Reserved wordsif, else, try, throw, skip, stop, fn, return, import, pub, lock, obj (only these twelve)

Sections