Expand packages and raw Engine write-up.

This commit is contained in:
Stephen Chung
2020-08-23 17:22:39 +08:00
parent 196e145c96
commit e2f271644a
10 changed files with 127 additions and 12 deletions

View File

@@ -1,11 +1,11 @@
Create a Rust Anonymous Function from a Rhai Function
===================================================
Create a Rust Closure from a Rhai Function
=========================================
{{#include ../links.md}}
It is possible to further encapsulate a script in Rust such that it becomes a normal Rust function.
Such an _anonymous function_ is basically a boxed closure, very useful as call-back functions.
Such a _closure_ is very useful as call-back functions.
Creating them is accomplished via the `Func` trait which contains `create_from_script`
(as well as its companion method `create_from_ast`):
@@ -30,7 +30,7 @@ let func = Func::<(i64, String), bool>::create_from_script(
"calc" // the entry-point function name
)?;
func(123, "hello".to_string())? == false; // call the anonymous function
func(123, "hello".to_string())? == false; // call the closure
schedule_callback(func); // pass it as a callback to another function