Merge branch 'bug-fixes'

This commit is contained in:
Stephen Chung
2021-09-24 09:27:45 +08:00
7 changed files with 83 additions and 27 deletions

View File

@@ -71,6 +71,47 @@ For those who actually want their own language
* Extend the language with [custom syntax](https://rhai.rs/book/engine/custom-syntax.html).
Example
-------
The [`scripts`](https://github.com/rhaiscript/rhai/tree/master/scripts) subdirectory contains sample Rhai scripts.
Below is the standard _Fibonacci_ example for scripting languages:
```js
// This Rhai script calculates the n-th Fibonacci number using a really dumb algorithm
// to test the speed of the scripting engine.
const TARGET = 28;
const REPEAT = 5;
fn fib(n) {
if n < 2 {
n
} else {
fib(n-1) + fib(n-2)
}
}
print(`Running Fibonacci(${TARGET}) x ${REPEAT} times...`);
print("Ready... Go!");
let result;
let now = timestamp();
for n in range(0, REPEAT) {
result = fib(TARGET);
}
print(`Finished. Run time = ${now.elapsed} seconds.`);
print(`Fibonacci number #${TARGET} = ${result}`);
if result != 317_811 {
print("The answer is WRONG! Should be 317,811!");
}
```
Project Site
------------