5.1 KiB
5.1 KiB
Example Scripts
{{#include ../../links.md}}
Language Feature Scripts
There are also a number of examples scripts that showcase Rhai's features, all in the scripts
folder:
Script | Description |
---|---|
array.rhai |
[Arrays] |
assignment.rhai |
Variable declarations |
comments.rhai |
Just comments |
for1.rhai |
for loops |
for2.rhai |
for loops on [arrays] |
function_decl1.rhai |
A [function] without parameters |
function_decl2.rhai |
A [function] with two parameters |
function_decl3.rhai |
A [function] with many parameters |
if1.rhai |
if example |
loop.rhai |
Count-down loop in Rhai, emulating a do .. while loop |
oop.rhai |
Simulate [object-oriented programming (OOP)][OOP] |
op1.rhai |
Just simple addition |
op2.rhai |
Simple addition and multiplication |
op3.rhai |
Change evaluation order with parenthesis |
string.rhai |
[String] operations |
strings_map.rhai |
[String] and [object map] operations |
while.rhai |
while loop |
Benchmark Scripts
The following scripts are for benchmarking the speed of Rhai:
Scripts | Description |
---|---|
speed_test.rhai |
A simple program to measure the speed of Rhai's interpreter (1 million iterations). |
primes.rhai |
Use Sieve of Eratosthenes to find all primes smaller than a limit. |
fibonacci.rhai |
Calculate the n-th Fibonacci number using a really dumb algorithm. |
mat_mul.rhai |
Matrix multiplication test to measure the speed of multi-dimensional array access. |
Running Example Scripts
To run the scripts, either make a tiny program or use of the rhai_runner
example:
cargo run --example rhai_runner scripts/any_script.rhai