Fix scripts.

This commit is contained in:
Stephen Chung 2021-04-16 10:33:55 +08:00
parent 8da4c0c2b2
commit c5128e15d5
3 changed files with 10 additions and 15 deletions

View File

@ -7,14 +7,8 @@ Testing scripts written in Rhai.
How to Run How to Run
---------- ----------
Compile the `rhai-run` example: Run scripts using the `rhai-run` tool:
```bash ```sh
cargo build --example rhai-run cargo run --bin rhai-run ./scripts/test_script_to_run.rhai
```
Run it:
```bash
./target/debug/examples/rhai-run ./scripts/test_script_to_run.rhai
``` ```

View File

@ -8,4 +8,4 @@ let /* I am a spy in a variable declaration! */ x = 5;
/* look /* at /* that, /* multi-line */ comments */ can be */ nested */ /* look /* at /* that, /* multi-line */ comments */ can be */ nested */
/* surrounded by */ this_is_not_a_comment = true // comments /* surrounded by */ let this_is_not_a_comment = true // comments

View File

@ -1,7 +1,8 @@
// This script calculates the n-th Fibonacci number using a really dumb algorithm // This script calculates the n-th Fibonacci number using a really dumb algorithm
// to test the speed of the scripting engine. // to test the speed of the scripting engine.
const target = 28; const TARGET = 28;
const REPEAT = 5;
fn fib(n) { fn fib(n) {
if n < 2 { if n < 2 {
@ -11,19 +12,19 @@ fn fib(n) {
} }
} }
print("Running Fibonacci(28) x 5 times..."); print(`Running Fibonacci(28) x ${REPEAT} times...`);
print("Ready... Go!"); print("Ready... Go!");
let result; let result;
let now = timestamp(); let now = timestamp();
for n in range(0, 5) { for n in range(0, REPEAT) {
result = fib(target); result = fib(TARGET);
} }
print(`Finished. Run time = ${now.elapsed} seconds.`); print(`Finished. Run time = ${now.elapsed} seconds.`);
print(`Fibonacci number #${target} = ${result}`); print(`Fibonacci number #${TARGET} = ${result}`);
if result != 317_811 { if result != 317_811 {
print("The answer is WRONG! Should be 317,811!"); print("The answer is WRONG! Should be 317,811!");