Luna is an interpreted, dynamically typed scripting language implemented as a C++20 module. It uses a recursive descent parser and an AST-walking interpreter.
Luna supports the following value types:
| Type | Description | Example |
|---|---|---|
| None | Represents the absence of value | none |
| Boolean | Logical true or false | true, false |
| Integer | 64-bit signed integer | 42 |
| Number | 64-bit floating point | 3.14159 |
| Symbol | Interned identifier string | #identifier |
| String | Text sequence | "hello" |
| List | Ordered generic collection | [1, 2, "a"] |
| Table | Key-value associative array | { x: 10, y: 20 } |
Variables are declared using the var keyword.
var x = 100;
var message = "Hello";Luna provides standard branching and looping constructs.
// Conditional
if (x > 50) {
x = x - 1;
} else {
x = x + 1;
}
// Loop
while (x > 0) {
if (x == 10) break;
if (x == 20) continue;
x = x - 1;
}Functions are first-class citizens. They support optional parameters with default values.
fn add(a, b: 1) {
return a + b;
}
// Usage
var result = add(10); // b defaults to 1Errors are structural exceptions that propagate up the call stack.
try {
throw "An error occurred";
} catch (e) {
// 'e' contains the thrown value
}The language includes operators for runtime type inspection and conversion.
var x = 10;
// Type Check
if (x is integer) {
// Conversion
var s = x as string;
}
// Type Query
var t = typeof(x); // returns #integer