Refine code and docs.
This commit is contained in:
@@ -24,7 +24,21 @@ engine.on_progress(|&count| { // parameter is '&u64' - number of operations al
|
||||
|
||||
The closure passed to `Engine::on_progress` will be called once for every operation.
|
||||
Return `Some(token)` to terminate the script immediately, with the provided value
|
||||
(any [`Dynamic`] value) passed to `EvalAltResult::ErrorTerminated` as a termination token.
|
||||
(any [`Dynamic`]) acting as a termination token.
|
||||
|
||||
|
||||
Termination Token
|
||||
-----------------
|
||||
|
||||
The [`Dynamic`] value returned by the closure for `Engine::on_progress` is a _termination token_.
|
||||
A script that is manually terminated returns with `Err(EvalAltResult::ErrorTerminated)`
|
||||
wrapping this value.
|
||||
|
||||
The termination token is commonly used to provide information on the _reason_ or _source_
|
||||
behind the termination decision.
|
||||
|
||||
If the termination token is not needed, simply return `Some(().into())` to terminate the script
|
||||
run with [`()`] as the token.
|
||||
|
||||
|
||||
Operations Count vs. Progress Percentage
|
||||
|
@@ -29,8 +29,9 @@ due to 64-bit arithmetic requiring more CPU cycles to complete.
|
||||
Minimize Size of `Dynamic`
|
||||
-------------------------
|
||||
|
||||
Turning on [`no_float`] and [`only_i32`] on 32-bit targets makes the critical [`Dynamic`] data type only 8 bytes long.
|
||||
Normally [`Dynamic`] can be up to 16 bytes (e.g. on x86/x64 CPU's) in order to hold an `i64` or `f64`.
|
||||
Turning on [`no_float`] or [`f32_float`] and [`only_i32`] on 32-bit targets makes the critical [`Dynamic`]
|
||||
data type only 8 bytes long.
|
||||
Normally [`Dynamic`] can be up to 12-16 bytes in order to hold an `i64` or `f64`.
|
||||
|
||||
A small [`Dynamic`] helps performance due to better cache efficiency.
|
||||
|
||||
|
@@ -42,13 +42,14 @@ are typically used for a WASM build:
|
||||
| Feature | Description |
|
||||
| :-----------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [`unchecked`] | When a WASM module panics, it doesn't crash the entire web app; however this also disables [maximum number of operations] and [progress] tracking so a script can still run indefinitely - the web app must terminate it itself. |
|
||||
| [`only_i32`] | JavaScript has only one `number` type and we're only supporting `wasm32` here (so far). |
|
||||
| [`only_i32`] | WASM supports 32-bit and 64-bit integers, but most scripts will only need 32-bit. |
|
||||
| [`f32_float`] | WASM supports 32-bit single-precision and 64-bit double-precision floating-point numbers, but single-precision is usually fine for most uses. |
|
||||
| [`no_module`] | A WASM module cannot load modules from the file system, so usually this is not needed, but the savings are minimal; alternatively, a custom [module resolver] can be provided that loads other Rhai scripts. |
|
||||
|
||||
The following features are typically _not_ used because they don't make sense in a WASM build:
|
||||
|
||||
| Feature | Why unnecessary |
|
||||
| :-----------: | ------------------------------------------------------------------ |
|
||||
| [`sync`] | WASM is single-threaded. |
|
||||
| [`no_std`] | `std` lib works fine with WASM. |
|
||||
| [`internals`] | WASM usually doesn't need to access Rhai internal data structures. |
|
||||
| Feature | Why unnecessary |
|
||||
| :-----------: | ------------------------------------------------------------------------------------------------------ |
|
||||
| [`sync`] | WASM is single-threaded. |
|
||||
| [`no_std`] | `std` lib works fine with WASM. |
|
||||
| [`internals`] | WASM usually doesn't need to access Rhai internal data structures, unless you are walking the [`AST`]. |
|
||||
|
@@ -17,7 +17,7 @@ more control over what a script can (or cannot) do.
|
||||
| `sync` | no | restricts all values types to those that are `Send + Sync`. Under this feature, all Rhai types, including [`Engine`], [`Scope`] and [`AST`], are all `Send + Sync` |
|
||||
| `no_optimize` | no | disables [script optimization] |
|
||||
| `no_float` | no | disables floating-point numbers and math |
|
||||
| `f32_float` | no | sets the system floating-point type to `f32` instead of `f64` |
|
||||
| `f32_float` | no | sets the system floating-point type to `f32` instead of `f64`. `FLOAT` is set to `f32` |
|
||||
| `only_i32` | no | sets the system integer type to `i32` and disable all other integer types. `INT` is set to `i32` |
|
||||
| `only_i64` | no | sets the system integer type to `i64` and disable all other integer types. `INT` is set to `i64` |
|
||||
| `no_index` | no | disables [arrays] and indexing features |
|
||||
|
Reference in New Issue
Block a user