KScript docs
EN

Getting started

Your first script

A script is a file that ends in .kscript. Save this as hello.kscript:

<echo>Hello, World!</echo>
echo "Hello, World!"

Then run it:

Shell
kscript hello.kscript

kscript run hello.kscript does the same. Anything after the script's name goes to the script as $args.

The main script

A folder's main script runs without naming it. Call it main.kscript, and kscript run (or just kscript) runs it:

CommandWhat it does
kscript runRuns main.kscript in this folder.
kscript run toolsRuns tools/main.kscript.
kscript . JoanRuns main.kscript with Joan as $args[0].

When there's no main.kscript, index.kscript is the main script. In a project, app.main in kscript.json names it instead, and the files are looked for beside kscript.json, so kscript run works from any folder in the project:

JSON
{
  "app": { "main": "tools/report.kscript" }   // kscript run now runs tools/report.kscript
}

The order is always the same: the script you name, then app.main, then main.kscript, main.ks.xml, index.kscript and index.ks.xml. kscript compile, kscript lib add and the editor's Run Project command find it the same way. With none of them, kscript run says what it looked for, and plain kscript shows the help.

A script runs from top to bottom, one statement per line. // starts a comment.