Expand description
§tinyscript - A small, C-like scripting language
tinyscript is considered to ba a superset of the scripting language defined in BehviorTree.CPP.
§Data types
| Type | Examples |
|---|---|
| Boolean | true/false |
| String | ‘hello world’ |
| Enum | RED, GREEN, BLUE |
| Numbers: | |
| Integer | 42 |
| Hexadecimal | 0x01 |
| Float | 3.14 |
Note: under the hood an Enum is always interpreted as its integer value.
§Boolean Values
Boolean values can be one of true or false.
Setting booleans:
val_a = true
val_b := !falseThe logical ! works with boolean literals.
!false is the equivalent of true.
val_a and val_b above are equivalent.
§Strings
Strings are enclosed by ‘…’.
§Enums
Enums must be registered to the Runtime before they can be used.
§Numbers
§Negative numbers
| Operator | Description |
|---|---|
| ~ | Negate |
§Statements
Examples:
print 42
print 42;
42; print 42; variable:= 42; (13 + 12)Multiple statements in a single script are separated by a semicolon. The last statements may or may not end with a semicolon.
§Assignment operators
Examples:
var_a := 42
var_b = 3.14
message = 'hello world'- The first line assigns the number 42 to the variable var_a.
- The second line assigns the number 3.14 to the variable var_b.
- The third line assigns the string “hello world” to the variable message.
§Arithmetic operators and parenthesis
Examples:
var_a := 7
var_b := 5
var_b *= 2
var_c := (var_a * 3) + var_bThe resulting values of var_a is 10 and var_c is 31.
The following operators are supported:
| Operator | Assign Operator | Description |
|---|---|---|
| + | += | Add |
| - | -= | Subtract |
| * | *= | Multiply |
| / | /= | Divide |
These operators can be used only on Number data types, only the addition acan also be used on Strings.
§Bitwise operators
These operators work only on integer and hexadecimal numbers. Using them with a string or float number will cause an error.
Examples:
value:= 0x7F
val_a:= value & 0x0F
val_b:= value | 0xF0The value of val_a is 0x0F (or 15); val_b is 0xFF (or 255).
| Operator | Description |
|---|---|
| | | Bitwise or |
| & | Bitwise and |
| ^ | Bitwise xor |
§Logic and comparison operators
Operators which return a boolean.
Example:
val_a := true
val_b := 5 > 3
val_c := (val_a == val_b)
val_d := (val_a && val_b) || !val_c| Operator | Description |
|---|---|
| && | Logic and |
| || | Logic or |
| ! | Negation |
| == | Equality |
| != | Inequality |
| < | Less |
| <= | Less equal |
| > | Greater |
| >= | Greater equal |
§Ternary operator if-then-else
Example:
val_b = (val_a > 1) ? 42 : 24The implementation follows the pattern of clox as described in Part III of crafting interpreters
Re-exports§
Modules§
- compiling
- Bytecode compiler for
tinyscript - error
tinyscripterrors- execution
- Virtual Machine of
tinyscript - runtime
- Runtime environment for
tinyscript
Structs§
- Default
Environment - A very simple default Environment for testing purpose and the REPL
Traits§
- Environment
- The trait for providing an
Environmentto aVMthat stores variables persistently and externally available. - Script
Enum - The trait for script enums.
Type Aliases§
- Const
String - An immutable thread safe
Stringtype see: Logan Smith.
Derive Macros§
- Script
Enum - Derive macro
ScriptEnum. Enables a Rust enum to be used in a ‘C’ like mannner within thetinyscriptlanguage.