Skip to content

v1.9.0

Compare
Choose a tag to compare
@schungx schungx released this 21 Aug 08:53
· 1021 commits to main since this release
00f84ef

The minimum Rust version is now 1.60.0 in order to use the dep: syntax for dependencies.

Bug fixes

  • switch cases with conditions that evaluate to constant () no longer optimize to false (should raise a type error during runtime).
  • Fixes concatenation of BLOB's and strings, where the BLOB's should be interpreted as UTF-8 encoded strings.
  • Capturing an unknown variable in a closure no longer panics.
  • Fixes panic in interpolated strings with constant expressions.
  • Using call_fn_raw on a function without evaluating the AST no longer panics on namespace-qualified function calls due to import statements not run.
  • Some reserved tokens (such as "?", "++") cannot be used in custom syntax; this is now fixed.

Breaking changes

  • The first closure passed to Engine::register_debugger now takes a single parameter which is a reference to the current Engine.

New features

New feature flags

  • A new feature flag, std, which is enabled by default, is added due to requirements from dependency crates.
  • A new feature flag, no_custom_syntax, is added to remove custom syntax support from Rhai for applications that do not require it (which should be most).

Module documentation

  • Comment lines beginning with //! (requires the metadata feature) are now collected as the script file's module documentation.
  • AST and Module have methods to access and manipulate documentation.

Output definition files

  • An API is added to automatically generate definition files from a fully-configured Engine, for use with the Rhai Language Server.

Short-hand to function pointers

  • Using a script-defined function's name (in place of a variable) implicitly creates a function pointer to the function.

Top-level functions

  • Crate-level functions rhai::eval, rhai::run, rhai::eval_file, rhai::run_file are added as convenient wrappers.

CustomType trait and TypeBuilder

  • A new volatile API, Engine::build_type, enables registration of the entire API of a custom type in one go, provided that the custom type implements the CustomType trait (which uses TypeBuilder to register the API functions).

Simpler Package API

  • It is now easier to register packages via the Package::register_into_engine and Package::register_into_engine_as API.
  • Defining a custom package with base packages is also much easier with a new syntax - put the new base packages after a colon.

Enhancements

switch statement

  • switch cases can now include multiple values separated by |.
  • Duplicated switch cases are now allowed.
  • The error ParseErrorType::DuplicatedSwitchCase is deprecated.
  • Ranges in switch statements that are small (currently no more than 16 items) are unrolled if possible.

Others

  • EvalContext::eval_expression_tree_raw and Expression::eval_with_context_raw are added to allow for not rewinding the Scope at the end of a statements block.
  • A new range function variant that takes an exclusive range with a step.
  • as_string is added to BLOB's to convert it into a string by interpreting it as a UTF-8 byte stream.
  • FnAccess::is_private, FnAccess::is_public, FnNamespace::is_module_namespace and FnNameSpace::is_global_namespace are added for convenience.
  • Iterator<Item=T> type for functions metadata is simplified to Iterator<T>.
  • Scope::remove is added to remove a variable from a Scope, returning its value.
  • The code base is cleaner by running it through Clippy.
  • ParseError::err_type and ParseError::position are added for convenience.
  • The source of an AST compiled from a script file is set to the file's path.
  • |> and <| are now reserved symbols.