v0.7 in progressEarly development
A strict, statically typed language with ActionScript roots
RuneScript keeps ActionScript's package, trace, int/uint,
try/catch and access modifiers, moves to a C-family syntax, and checks every type
before your program runs. It runs as a standalone CLI implemented in Go, and compiles to a JavaScript module for
the web with the same strict typing.
- Implemented in
- Go 1.25+
- Typing
- Static, explicit
- Runs as
- CLI, JavaScript, WebAssembly
// The smallest complete RuneScript program.
package main;
protected int main() {
trace("Hello, RuneScript!");
return 0;
}$ runescript run hello.rsc
Hello, RuneScript!// Advanced functions: callbacks, lambdas, nested functions, prototypes,
// and functions that return functions.
package examples.callbacks;
// A prototype: the definition is further down.
public int sumWith(int(int) f, int n);
public void forEach(int from, int to, void(int) body) {
for (int i = from; i <= to; i++) {
body(i);
}
}
public int(int) multiplier(int factor) {
// Functions do not capture variables, so each factor gets its own function.
private int times2(int x) { return x * 2; }
private int times3(int x) { return x * 3; }
if (factor == 2) {
return times2;
}
if (factor == 3) {
return times3;
}
return (int x) => x;
}
protected int main() {
// Pass a lambda as a callback.
forEach(1, 3, (int i) => trace("item", i));
// Store functions in variables and pass named functions around.
int(int) square = (int x) => x * x;
trace("sum of squares 1..4:", sumWith(square, 4));
trace("sum of triples 1..5:", sumWith(multiplier(3), 5));
trace("double 21:", multiplier(2)(21));
// Nested functions, with a prototype for mutual recursion.
private bool isEven(int n);
private bool isOdd(int n) {
if (n == 0) { return false; }
return isEven(n - 1);
}
private bool isEven(int n) {
if (n == 0) { return true; }
return isOdd(n - 1);
}
trace("7 is odd:", isOdd(7));
return 0;
}
public int sumWith(int(int) f, int n) {
int total = 0;
for (int i = 1; i <= n; i++) {
total += f(i);
}
return total;
}$ runescript run callbacks.rsc
item 1
item 2
item 3
sum of squares 1..4: 30
sum of triples 1..5: 45
double 21: 42
7 is odd: true// The std:string standard library package (Go's strings, camelCase names).
package examples.strings;
use "std:string";
public string slug(string title) {
string s = string.toLower(string.trimSpace(title));
return string.replaceAll(s, " ", "-");
}
protected int main() {
string title = " Hello RuneScript World ";
trace("slug:", slug(title));
string path = "assets/runescript.svg";
if (string.hasSuffix(path, ".svg")) {
trace("image:", string.trimSuffix(path, ".svg"));
}
int slash = string.index(path, "/");
trace("first slash at byte", slash);
trace("vowels in title:", string.count(title, "o") + string.count(title, "e"));
trace(string.repeat("=", 20));
return 0;
}$ runescript run strings.rsc
slug: hello-runescript-world
image: assets/runescript
first slash at byte 6
vowels in title: 4
====================Familiar shape, stricter rules
If you've written ActionScript, Java, C# or TypeScript, RuneScript reads the way you expect. It just refuses to guess.
Types first, C-family syntax
Write public int add(int a, int b). Every function starts with an access modifier, types come before names, and semicolons are required.
Strict by default
Nothing is implicitly any. Signed and unsigned integers never mix silently, and conditions must be bool.
No silent overflow
Integer arithmetic is exact. Overflow and division by zero stop the program with a located runtime error instead of wrapping.
Errors that point at the problem
Every diagnostic has a stable code, a line and column, the source line with a caret, and help text that says how to fix it.
Functions as values
Function types like int(int, int), lambdas, callbacks, nested functions, prototypes, and functions that return functions.
Docs that compile
Every program in the guide is compiled by the test suite, and every example's output is checked. If the docs drift, the build fails.
Mistakes surface before the program runs
Assigning a signed value to a uint is a compile-time error, not a silent wraparound. The checker tells
you exactly where, and what to do about it.
- Stable error codes, such as
ASX-TYPE-004 -
line:colpositions, with the source line and a caret - Help text with a concrete fix
package examples.errors;
protected int main() {
sint signedValue = -10;
uint unsignedValue = signedValue; // expect: ASX-TYPE-004 9:26
return 0;
}$ runescript check signedness_error.rsc
examples/signedness_error.rsc:9:26: error ASX-TYPE-004: Cannot assign signed integer 'sint' to unsigned integer 'uint'.
uint unsignedValue = signedValue; // expect: ASX-TYPE-004 9:26
^^^^^^^^^^^
help: Use an explicit checked conversion, (uint) x, or change the destination type.Coming from ActionScript 3
RuneScript is inspired by AS3 but isn't source-compatible with it. Declarations put the type first, and there's no function or var.
ActionScript 3
package {
public class Greeter {
public function sayHi(message:String, times:int):void {
for (var i:int = 0; i < times; i++) {
trace(message);
}
}
}
}RuneScript
package main;
public void sayHi(string message, int times) {
for (int i = 0; i < times; i++) {
trace(message);
}
}
protected int main() {
sayHi("hi", 2);
return 0;
}| Code | ActionScript 3 | RuneScript |
|---|---|---|
var u:uint = -1; | Becomes 4294967295 | Compile error ASX-TYPE-007 |
uint ← int variable | Converted silently | Compile error ASX-TYPE-004 |
int + uint | Converted silently | Compile error ASX-TYPE-011 |
int.MAX_VALUE + 1 | Wraps to a negative number | Runtime error ASX-RUN-002 |
7 / 2 | 3.5 | 3 (integer division) |
Where it stands
RuneScript is small on purpose. A feature counts as done only when tests show it working.
Works now
- Packages and access-modified functions
- int / sint, uint, float / float32 / float64, bool, string, void
- if, while, for, for each, break, continue, return
- Function types, lambdas, callbacks
- use "std:string" (Go's strings package, with split, join, and callbacks)
- Strings: + and $"{count} files"; char; Array<T> with checked indexing
- int8 … uint64, hex and binary literals, bit operators
- use "std:math", with bit-identical results on both targets
- Structs with value semantics, methods, and constructors
- SemVer metadata for module files
- Go closure execution for the CLI
- Graphics with raylib on desktop and in the browser
- Classes: fields, methods, constructors; objects by reference with new
- Multi-file programs: use "pkg" and use "./file"
- Files, input, and arguments: use "std:fs", "std:io", "std:process", "std:path"
- Data: use "std:json", "std:csv", "std:matrix", "std:semver"
- Checked conversions: (int) 64.3, (float) "64.7"
- throw, try / catch / finally, catchable runtime errors
- Located compile-time and runtime errors
- Compiles to JavaScript (runescript build), with source maps
- Calls JavaScript through extern, checking every value that comes back
- Warnings, with -Werror and --allow
- Live reload: runescript dev, run --watch
- Web pages: checked HTML/SVG templates, $foreach lists, runes (signals), events
- Editors: VS Code, Vim, Neovim, Emacs, through the language server (runescript lsp)
Planned
- Class inheritance and interfaces
- Graphics audio
- Workspace-wide rename
Run your first program
You need Go 1.25 or newer. Build the CLI, then run any example.
Get the source
$ git clone https://github.com/AurielSolaris/runescript.git && cd runescriptBuild the CLI
$ go build -o runescript ./cmd/runescriptRun a program
$ ./runescript run examples/hello.rsc Hello, RuneScript!