Choose a language for a script
The right language for the job, and proof the engine accepts your file as that language.
Why bother
Section titled “Why bother”Picking a language by preference and finding out at deploy time that the engine rejects it is an expensive way to learn the list.
The languages
Section titled “The languages”--runtime | Use for |
|---|---|
javascript | The default choice. Full control flow, objects, the host namespaces |
lua | Small, fast, familiar to game and embedded teams |
starlark | Deterministic and sandboxed by construction — a good fit for untrusted logic |
expr | A single expression, not a program |
go | Interpreted Go, for teams already writing it |
wasm | A precompiled module |
Step 1 — prove it compiles
Section titled “Step 1 — prove it compiles”kis script compile transform.js --runtime javascriptCompiling with javascript runtime...✓ Compilation successful (95.377µs)Source size: 59 bytesStep 2 — read a rejection as information
Section titled “Step 2 — read a rejection as information”Compiling the same JavaScript file under each language is a quick way to see what each one is:
$ kis script compile hello.js -r luaerror: hello.js line:1(column:17) near '{': syntax error
$ kis script compile hello.js -r exprerror: unexpected token Identifier("main") (1:10)
$ kis script compile hello.js -r wasmerror: invalid magic numberEach failure names the real reason: Lua does not use braces that way, expr wants an expression
rather than a function declaration, and wasm expects a binary rather than text.
Starlark accepting a JavaScript-shaped function is not a licence to write JavaScript in it — the syntaxes overlap far enough to compile and diverge quickly after that.
Where the choice is recorded
Section titled “Where the choice is recorded”A language chosen at the terminal is not a decision anyone else can see. Put it where it runs.
- name: transform script: language: starlark file: ./classify.star namespaces: json,string setvar: classifiedlanguage: is explicit even when the extension already implies it — the file may be renamed, and
the flow is what actually decides. Pairing it with namespaces: is the combination worth reaching
for on generated code: a language that contributes no authority, and a grant that gives it none.
kis script run classify.star --runtime starlark --namespaces none--runtime overrides the extension. Use it while you are choosing; move the answer into the flow
once you have chosen.
Choosing
Section titled “Choosing”| The script | Language |
|---|---|
| Calls host namespaces, has real control flow | javascript |
| Is untrusted or generated, and should be constrained by construction | starlark |
| Is one condition or one calculation | expr |
| Is CPU-heavy and precompiled elsewhere | wasm |
| Is maintained by a team that already writes Lua or Go | lua or go |
Verify
Section titled “Verify”Compile under the language you will actually configure, not the one you assume. A file that
compiles as javascript says nothing about whether it compiles as starlark.