v1.11.0
This is a large release containing numerous new features, bug fixes and speed improvements.
Speed Improvements
- Due to a code refactor, built-in operators for standard types now run even faster, in certain cases by 20-30%.
Bug fixes
Engine::parse_jsonnow returns an error on unquoted keys to be consistent with JSON specifications.importstatements insideevalno longer cause errors in subsequent code.- Functions marked
globalinimported modules with no alias names now work properly. - Incorrect loop optimizations that are too aggressive (e.g. unrolling a
do { ... } until truewith abreakstatement inside) and cause crashes are removed. Dynamic::isnow works properly for shared values.
Breaking changes
NativeCallContext::newis completely deprecated and unimplemented (always panics) in favor of new API's.
New features
Dynamic detection API
- New methods are added to
Dynamicin the form ofis_XXX()whereXXXis a type (e.g.is_int,is_unit,is_bool,is_array). - This new API is to make it easier to detect the data type, instead of having to call
is::<XXX>().
Loop expressions
- Loops (such as
loop,do,whileandfor) can now act as expressions, with thebreakstatement returning an optional value. - Normal loops return
()as the value. - Loop expressions can be enabled/disabled via
Engine::set_allow_loop_expressions
Static hashing
- It is now possible to specify a fixed seed for use with the
ahashhasher, via a static functionrhai::config::hashing::set_ahash_seedor an environment variable (RHAI_AHASH_SEED), in order to force static (i.e. deterministic) hashes for function signatures. - This is necessary when using Rhai across shared-library boundaries.
- A build script is used to extract the environment variable (
RHAI_AHASH_SEED, if any) and splice it into the source code before compilation.
no_time for no timestamps
- A new feature,
no_time, is added to disable support for timestamps. - This may be necessary when building for architectures without time support, such as raw WASM.
Serializable Scope
Scopeis now serializable and deserializable viaserde.
Store and recreate NativeCallContext
- A convenient API is added to store a
NativeCallContextinto a newNativeCallContextStoretype. - This allows a
NativeCallContextto be stored and recreated later on.
Call native Rust functions in NativeCallContext
NativeCallContext::call_native_fnis added to call registered native Rust functions only.NativeCallContext::call_native_fn_rawis added as the advanced version.- This is often desirable as Rust functions typically do not want a similar-named scripted function to hijack the process -- which will cause brittleness.
Custom syntax improvements
- The look-ahead symbol for custom syntax now renders a string literal in quotes (instead of the generic term
string). - This facilitates more accurate parsing by separating strings and identifiers.
Limits API
- Methods returning maximum limits (e.g.
Engine::max_string_len) are now available even underunchecked. - This helps avoid the proliferation of unnecessary feature flags in third-party library code.
Enhancements
parse_jsonfunction is added to parse a JSON string into an object map.Error::ErrorNonPureMethodCallOnConstantis added which is raised when a non-pure method is called on a constant value.