Packaged Utilities
A number of Rhai-driven tools can be found in the src/bin
directory:
It is possible to turn these tools into Domain-Specific Tools.
Tool | Required feature(s) | Description |
---|---|---|
rhai-run | runs Rhai script files | |
rhai-repl | rustyline | a simple REPL tool |
rhai-dbg | debugging | the Rhai Debugger |
Some bin tools require certain features and will not be built by default without those features set.
For convenience, a feature named bin-features
is available which is a combination of
the following:
Feature | Description |
---|---|
decimal | support for decimal numbers |
metadata | access functions metadata |
serde | export functions metadata to JSON |
debugging | required by rhai-dbg |
rustyline | required by rhai-repl |
Install Tools
To install all these tools (with full features), use the following command:
cargo install --path . --bins --features bin-features
or specifically:
cargo install --path . --bin sample_app_to_run --features bin-features
Run a Tool from Cargo
Tools can also be run with the following cargo
command:
cargo run --features bin-features --bin sample_app_to_run
Tools List
rhai-repl
is a particularly useful tool – it allows one to interactively try out
Rhai’s language features in a standard REPL (Read-Eval-Print Loop).
Filenames passed to it as command line arguments are run and loaded as Rhai scripts before the REPL starts.
Test functions
The following test functions are pre-registered, via Engine::register_fn
, into rhai-repl
.
They are intended for testing purposes.
Function | Description |
---|---|
test(x: i64, y: i64) | returns a string with both numbers |
test(x: &mut i64, y: i64, z: &str) | displays the parameters and add y to x |
Example
The following command first runs three scripts – init1.rhai
, init2.rhai
and init3.rhai
–
loading the functions defined in each script into the global namespace.
Then it enters an REPL, which can call the above functions freely.
rhai-repl init1.rhai init2.rhai init3.rhai
Use rhai-run
to run Rhai scripts.
Filenames passed to it as command line arguments are run in sequence as Rhai scripts.
Example
The following command runs the scripts script1.rhai
, script2.rhai
and script3.rhai
in order.
rhai-run script1.rhai script2.rhai script3.rhai
Use rhai-dbg
to debug a Rhai script.
Filename passed to it will be loaded as a Rhai script for debugging.
Example
The following command debugs the script my_script.rhai
.
rhai-dbg my_script.rhai