Your first project
This page builds one package and imports it from TypeScript, Python, and Go. It takes a few minutes and needs no test runner.
1. Create the project
lt init money
cd money
lt init writes:
lt.toml
src/money.lt
.gitignore
The generated src/money.lt is a starting package. Replace it with:
package money {
export struct Price {
amount: Int
currency: Str
}
export fn format_price(p: Price) -> Str {
`${p.amount / 100}.${p.amount % 100} ${p.currency}`
}
export fn add(a: Price, b: Price) -> Price {
Price(amount: a.amount + b.amount, currency: a.currency)
}
}
Rules that matter here:
- A file contains exactly one
packageblock. A file without one, or with more than one, is a compile error. - Fields are named at construction:
Price(amount: 1250, currency: "IDR"). format_priceis a receiver function because its first parameter is a struct.p.format_price()is the same call.exportmakes a declaration part of the package API. Without it, the declaration is private.- Local imports use a path without
.lt:import money "./money".
lt.toml starts empty and holds external dependencies:
[dependencies]
2. Check and build
lt check src/
lt fmt src/
lt build -t ts src/money.lt --out out
lt build -t py src/money.lt --out out
lt build -t go src/money.lt --out out
lt check resolves imports and type-checks the graph. lt fmt writes the canonical form. lt build never writes lt.lock; only lt update does.
The build writes one host module per package:
out/ts/src/money.ts
out/py/gen/money.py
out/go/gen/money/money.go
Each target also gets its inline runtime and project metadata. See Backends for the exact layout.
3. Call it from the host language
TypeScript
import { Price, formatPrice } from "./out/ts/src/money";
const total = formatPrice(new Price({ amount: 1250n, currency: "IDR" }));
console.log(total); // 12.50 IDR
Int maps to bigint; snake_case becomes camelCase.
Python
from gen.money import Price, format_price
total = format_price(Price(amount=1250, currency="IDR"))
print(total) # 12.50 IDR
Run it with out/py on PYTHONPATH.
Go
package main
import (
"fmt"
money "linguatungga/gen/money"
)
func main() {
total := money.FormatPrice(money.Price{Amount: 1250, Currency: "IDR"})
fmt.Println(total) // 12.50 IDR
}
Go gets one package directory per LT package. Put the generated out/go module on your module path, or copy the packages into your project.
4. Add a dependency
External code is declared in lt.toml, then imported by key:
lt add foo --git https://github.com/foo/bar --version "^1.2"
lt update --all
import user { User } "foo/src/user"
See Packages and dependencies.
5. Next
- Add tests with
test "…" { … }and run them withlt test -t <target> … --run. - Read the language guide for types,
match,Option,Result, and imports. - Use the playground to try a snippet without a local toolchain.