KonsolScript is a modern, lightweight embeddable scripting language built for tooling, automation, AI orchestration, and game scripting. Wire LLM APIs into automated pipelines, build AI-powered CLI tools, orchestrate multi-model workflows, or script interactive games — all with a clean, readable syntax that values clarity, portability, and extensibility.
| I want to… | Go to |
|---|---|
Write .ks scripts |
Scripting Guide |
| Extend the engine or write a plugin | Contributing Guide |
From beginner CLI tools to AI-powered pipelines — KonsolScript's modules and plugins cover a wide range of real-world apps:
File, Path, OS)CSV, Json, List)curl, Json, File)Regex, curl, Json)→ Full project ideas — beginner to advanced
#define and #include (file and plugin)Variables, types, literals, string interpolation, multi-line strings, comments, and struct (UDT) definitions.
| Op | Meaning |
|---|---|
+ |
Add / concat |
- |
Subtract |
* |
Multiply |
/ |
Divide |
% |
Modulo |
Use Math:Power(base, exp, out) for exponentiation — ^ is bitwise XOR.
+ on a string and any value concatenates both as strings.
| Op | Meaning |
|---|---|
== |
Equal |
!= |
Not Equal |
> |
Greater than |
>= |
Greater than or equal |
< |
Less than |
<= |
Less than or equal to |
| Op | Meaning |
|---|---|
&& |
logical AND |
|| |
logical OR |
! |
logical NOT |
Var:Boolean active = true;
Var:Boolean admin = false;
if (active == true && admin == false) {
Konsol:Print("active non-admin");
}
if (!admin) {
Konsol:Print("not an admin");
}
Var:Boolean allowed = (active == true || admin == true);
Logical operators are most useful inside conditions — see Control flow for if, while, for, switch, and more.
| Op | Meaning |
|---|---|
& |
bitwise AND |
^ |
bitwise XOR |
\| |
bitwise OR |
~ |
bitwise NOT (complement) |
<< |
left shift |
>> |
right shift |
Operands are truncated to 64-bit integer before the operation; the result is stored as Number.
Var:Number flags = 1 | 4; // 5
Var:Number masked = flags & 3; // 1
Var:Number flipped = 12 ^ 10; // 6
Var:Number shifted = 1 << 8; // 256
Var:Boolean isOdd = (n & 1) == 1;
| Op | Meaning |
|---|---|
= |
assign |
-= |
subtract then assign |
+= |
add then assign |
*= |
multiply then assign |
/= |
divide then assign |
%= |
modulus then assign |
++ |
increment (add 1) |
-- |
decrement (subtract 1) |
condition ? valueIfTrue : valueIfFalse
Var:Number x = 10;
Var:String label = x > 0 ? "positive" : "non-positive";
Konsol:Print(label); // positive
Ternary has the lowest precedence after ||. Nesting is allowed.
Unary (`-`, `!`, `~`) → `* / %` → `+ -` → `<< >>` → comparison → `&` → `^` → `|` → `&&` → `||` → ternary `?:`
See Control flow for if / else if / else, while, for, break, continue, switch / case, and foreach.
function greet(String name) {
Konsol:Print("Hello, " + name);
}
function add(Number a, Number b) : Number {
return a + b;
}
greet("world");
Var:Number result = add(3, 4);
Parameter types can be written as Number x or Var:Number x — both work.
Return type annotation (: Number, : String, : Boolean) is required for non-void functions. Void functions omit the suffix.
Functions can be called in expressions:
Var:Number n = add(1, 2) * 10;
Recursion is supported. Each call gets its own local scope; locals are erased after the call.
If the script defines a main function, it is called automatically. Global variable declarations are executed first to initialise globals.
Var:Number count = 0; // initialised before main() runs
function main() {
Konsol:Print(count);
}
If there is no main, all top-level statements execute in order.
Fixed-size typed arrays. Size is set at declaration and does not change.
Full OOP with fields and methods. Every user-defined class implicitly extends Object.
Object is the implicit root of every user-defined class, providing getType(), toString(), and isInstanceOf(). Exception extends Object and is used in try / catch.
try {
throw "something went wrong";
} catch (String e) {
Konsol:Print("Caught: " + e);
} finally {
Konsol:Print("always runs");
}
throw accepts any expression; the string value becomes the exception message.(String e) is optional — bare catch { } works too.finally is optional.KonsolScript Error (line 5): undefined variable 'total'
5 | Konsol:Print(total);
| ^^^^^
Uncaught throw exceptions show the same context plus a full stack trace:
Uncaught exception (line 12): something went wrong
12 | throw "something went wrong";
Stack trace:
at inner (called from line 8)
at outer (called from line 3)
at main
Calling a method on a class that was never registered raises a clear error:
Runtime error at line 3: unknown class 'Sample' — missing #include?
All stdlib calls use the Module:Method(args) syntax. Methods that return a value follow the ByRef convention: pre-declare a receiver variable and pass it as the last argument.
Var:Number h;
Time:GetHour(h);
Konsol:Print(h); // current hour
| Module | Description |
|---|---|
| Konsol | Terminal I/O, process control, ASCII utilities |
| Math | Numeric operations, trigonometry, random |
| String | String manipulation — trim, split, replace, compare |
| File | File open/read/write/close |
| Time | Wall-clock time, process timer |
| List | Dynamic resizable typed array |
| Map | String-keyed dictionary |
| Json | Parse, build, and serialize JSON |
| Path | Path manipulation and filesystem queries |
| OS | Working directory, env vars, process control, dir listing |
| Regex | Pattern matching and capture groups |
| Date | Unix-timestamp date arithmetic and formatting |
| Hash | MD5, SHA-256, Base64 |
| CSV | Parse, build, and serialize CSV |
Plugins are shared libraries that extend KonsolScript with new modules — no recompile of minks needed.
Install with minks install <name>.
| Plugin | Description |
|---|---|
| curl | HTTP client — GET, POST, PUT, DELETE |
| sqlite | SQLite database (no external dependency) |
| mysql | MySQL / MariaDB database |
| zip | Zip archive read/write |
| net | LAN TCP networking |
MathException — catch with catch (MathException e).ArrayException — catch with catch (ArrayException e). e.code holds the attempted index.#include "file.ks" is fully supported with transitive includes and include-guard deduplication. See Var — Preprocessor.main() are properly scoped and cleaned up after main returns.Math:Random uses srand/rand; not cryptographically secure. Use Math:Seed(n) for reproducible sequences.String:Mid uses 1-based start index (like BASIC), not 0-based.