The `luma` command
luma <command> <file.luma> [options]Commands
luma run <file> [flags...]
Runs the program in the interpreter. Everything after the file name goes to the program, for its flags:
luma run hello.luma
luma run app.luma --name=Ann --port 9000A program that reads input with prompt reads it from the terminal, or from a file or another program: luma run greet.luma < answers.txt. The same goes for a compiled program: ./greet < answers.txt.
luma run -sandbox <file>
Runs a program that may only compute, as the Luma playground does: no files or folders, no network (tcp, http, grpc, databases), no other programs (shell), and no import, since a program here is one file. Environment variables look empty, so env.get("HOME", "none") gives "none".
luma run -sandbox hello.lumaEverything else works as always: text, lists and maps, JSON, dates, random, crypto, uuid, HTML, wait and spawn, and prompt, which reads stdin. A program that tries to reach the system gets error 18 at that moment, at its line, and can catch it with try:
main.luma:2:24: runtime error: files and folders aren't available in the playground-sandbox also works with luma ir and luma asm, which then refuse import. It isn’t for luma build: a built program runs outside Luma.
luma test [folder | file] [-build] [-run names]
Runs the tests: the fn test_...() functions in the *_test.luma files of a folder (the current one if none is given), or of one file. It exits with code 1 if a test failed. See Testing.
luma test # the tests in this folder
luma test hello.luma # the tests of hello.luma, in hello_test.luma
luma test -build # compiled instead of interpreted
luma test -run cart,total # only the tests with "cart" or "total" in their namesluma build <file> [-o <output>] [-target <os>]
Compiles the program into a native executable.
luma build hello.luma # creates ./hello (or hello.exe on Windows)
luma build hello.luma -o greet # creates ./greet
luma build hello.luma -target windows # creates hello.exe
luma build hello.luma -target linux -o app # creates ./app| Option | Meaning | Default |
|---|---|---|
-o <name> | name of the executable | the source file name without .luma (plus .exe for Windows) |
-target <os> | linux or windows | the operating system you are running on |
-memcheck | build an executable that checks its memory and reports values never freed (slower; see Memory) | off |
Executables are for 64-bit x86 processors (x86-64 / AMD64).
luma help
Prints a summary of the commands.
luma doc [topic [section] | -s word]
The manual, built into luma: this documentation, shown in the terminal. It always matches the version of luma you have, and needs no files or internet.
luma doc # the contents: every page and topic
luma doc objects # a page
luma doc obj # a topic: a keyword, built-in or method leads to its page
luma doc lock # ... or to the section about it
luma doc objects init # one section of a page, by words of its title
luma doc -s circle # every line of the manual that mentions a wordA word that isn’t a topic is looked up anyway: luma doc recursion lists the sections that mention it, and a typo gets a suggestion (luma doc objetcs: did you mean objects?).
On a terminal the manual has colors, and a page longer than the screen opens in a pager: the program named by $PAGER, or less. Set NO_COLOR to turn colors off. Piped into a file or another program, it’s plain text.
luma lsp
The language server: editors start it to show errors while you type. See Editors.
Looking inside the compiler
These commands show what the compiler does with your program, one stage at a time. They’re useful for learning how a compiler works, and for understanding an error.
| Command | Shows |
|---|---|
luma tokens <file> | the words and symbols the compiler sees |
luma ast <file> | the syntax tree: how the program is structured |
luma ir <file> | the instructions for Luma’s internal stack machine |
luma asm <file> [-target <os>] | the x86-64 assembly code of the executable |
For example, for print(1 + 2 * 3):
$ luma ast calc.luma
Program
ExprStmt
Call print @1:1
Binary + @1:9
Int 1 @1:7
Binary * @1:13
Int 2 @1:11
Int 3 @1:15
$ luma ir calc.luma
strings:
slots: 0
code:
0000 PUSH_INT 1
0001 PUSH_INT 2
0002 PUSH_INT 3
0003 MUL
0004 ADD
0005 PRINT_INT
0006 HALTThe * sits deeper in the tree than +, so it is calculated first.
Exit codes
| Code | Meaning |
|---|---|
| 0 | the program finished normally |
| 1 | a compile error, or a runtime error such as division by zero; for luma test, a test that failed |
| 2 | luma was started without a command |
A compiled program exits with the same codes as luma run.