Crates.io | tinyscript |
lib.rs | tinyscript |
version | 0.2.0 |
created_at | 2025-07-19 06:39:37.600977+00 |
updated_at | 2025-08-29 14:25:53.363252+00 |
description | Tiny, C-like scripting language. |
homepage | https://github.com/stepkun/tinyscript |
repository | https://github.com/stepkun/tinyscript |
max_upload_size | |
id | 1759972 |
size | 115,743 |
tinyscript is considered to ba a superset of the scripting language defined in BehviorTree.CPP.
The implementation follows the pattern of clox
as described in Part III of crafting interpreters
use tinyscript::{Runtime, environment::DefaultEnvironment};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut runtime = Runtime::default();
let mut env = DefaultEnvironment::default();
let value = runtime.run("2 * 2 == 4", &mut env)?;
Ok(())
}
Licensed under either of
at your option.
Any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.
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 can be one of true
or false
.
Setting booleans:
val_a = true
val_b := !false
The logical !
works with boolean literals.
!false
is the equivalent of true
.
val_a
and val_b
above are equivalent.
Strings are enclosed by '...'.
Enums must be registered to the Runtime before they can be used.
Operator | Description |
---|---|
~ | Negate |
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.
Examples:
var_a := 42
var_b = 3.14
message = 'hello world'
Examples:
var_a := 7
var_b := 5
var_b *= 2
var_c := (var_a * 3) + var_b
The 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.
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 | 0xF0
The value of val_a
is 0x0F (or 15); val_b
is 0xFF (or 255).
Operator | Description |
---|---|
| | Bitwise or |
& | Bitwise and |
^ | Bitwise xor |
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 |
Example:
val_b = (val_a > 1) ? 42 : 24