Back to Rhai

Sample Applications

examples/README.md

1.24.04.2 KB
Original Source

Sample Applications

Standard Examples

ExampleDescription
arrays_and_structsshows how to register a Rust type and using it with arrays
callbackshows how to store a Rhai closure and call it later within Rust
custom_types_and_methodsshows how to register a Rust type and methods/getters/setters for it
custom_typesshows how to register a Rust type and methods/getters/setters using the CustomType trait.
definitionsshows how to generate definition files for use with the Rhai Language Server (requires the metadata feature)
hellosimple example that evaluates an expression and prints the result
pause_and_resumeshows how to pause/resume/stop an Engine running in a separate thread via an MPSC channel
reuse_scopeevaluates two pieces of code in separate runs, but using a common Scope
serdeexample to serialize and deserialize Rust types with serde (requires the serde feature)
simple_fnshows how to register a simple Rust function
stringsshows different ways to register Rust functions taking string arguments
threadingshows how to communicate in duplex with an Engine running in a separate thread via a pair of MPSC channels

Scriptable Event Handler With State Examples

Because of its popularity, included are sample implementations for the pattern Scriptable Event Handler With State in different styles.

ExampleHandler ScriptDescription
event_handler_mainevent_handler_main/script.rhaiMain Style
event_handler_jsevent_handler_js/script.rhaiJS Style
event_handler_mapevent_handler_map/script.rhaiMap Style

Running Examples

Examples can be run with the following command:

sh
cargo run --example {example_name}