XScripTH is a command-based scripting language and execution engine for .NET.
The main idea is simple: almost everything is a command. print, if, variables, functions, and other language features all follow the same basic rules instead of having their own special syntax.
Commands take comma-separated inputs and end with a terminator:
command input1, input2, input3;
Use ; when the next command should wait for this one to finish.
print "Hello, World!";
Use ;; to start a command without waiting for it to finish:
long-running-task;;
print "This can run straight away";
A command does not get special treatment just because it is built into the language. For example, if is still just a command with two inputs: a condition and something to run.
if (1 == 1), {
print "Condition met!";
};
Commands expect inputs of particular types. An input can be a literal, variable, expression, block, function, or the result of another command, as long as it produces the type the command needs.
That means there can be a few unusual but valid-looking ways to write the same idea:
if true, { print "Condition met!"; };
if (1 == 1), { print "Condition met!"; };
if { return true; }, { print "Condition met!"; };
if { return true; }, print "Condition met!"; ;
All four conditions result in a boolean value.
XScripTH checks types, but it does not silently convert values between unrelated types. For example, an integer is not automatically turned into a string.
Use an explicit cast command when a value should be converted. Casts are normal commands named after the target type, so they compose anywhere a command output is accepted:
int input; ;
string (5 + 5);
Type identifiers are case-insensitive.
| Type | Example |
|---|---|
| String | "Hello" |
| Char | 'A' |
| Boolean | true, false |
| Integer | 42 |
| Long | 42l |
| Float | 3.14f |
| Double | 3.14d |
| Decimal | 3.14m |
Use parentheses for math and boolean expressions:
print (2 + 3 * 4);
if (($count > 0) && true), {
print "count is positive";
};
Expressions can contain literals, variables, nested commands, function calls, blocks, and other expressions.
Declare a variable with var, update it with set, then reference it with $:
var $message, "Hello";
print $message;
set $message, "Goodbye";
print $message;
var $size, length $message; ;
A block groups commands without running them immediately. Blocks are useful when a command needs something to run later, such as the body of an if or while.
{
print "Doing some work...";
return true;
}
By default a block returns the result of its last entry. Use return to control what value that block produces.
Functions are named reusable blocks. Declare one with func, then refer to it with @.
func "greet_user", {
param $name, "string";
print $name;
};
@greet_user "Alice";
Functions must be declared before they are used.
if takes a boolean condition and something to run when the condition is true:
if true, {
print "Condition met!";
};
while takes a boolean condition and a something to run. The condition is evaluated before every iteration:
while true, {
print "Still running";
};
This README covers the language's main syntax and ideas. To see how the language works and how to add commands see TECHNICAL.