Rhai v1.5.0 Release Notes

  • This version adds a debugging interface, which can be used to integrate a debugger.

    0๏ธโƒฃ Based on popular demand, an option is added to throw exceptions when invalid properties are accessed on object maps (default is to return ()).

    Also based on popular demand, the REPL tool now uses a slightly-enhanced version of rustyline for line editing and history.

    ๐Ÿ› Bug fixes

    • ๐Ÿ‘ฏ In Scope::clone_visible, constants are now properly cloned as constants.
    • ๐Ÿ‘ป Variables introduced inside try blocks are now properly cleaned up upon an exception.
    • ๐Ÿ›  Off-by-one error in character positions after a comment line is now fixed.
    • Globally-defined constants are now encapsulated correctly inside a loaded module and no longer spill across call boundaries.
    • ๐Ÿ›  Type names display is fixed.
    • Exceptions thrown inside function calls now unwrap correctly when catch-ed.
    • ๐Ÿ›  Error messages for certain invalid property accesses are fixed.

    Script-breaking changes

    • For consistency with the import statement, the export statement no longer exports multiple variables.
    • Appending a BLOB to a string (via +, +=, append or string interpolation) now treats the BLOB as a UTF-8 encoded string.
    • Appending a string/character to a BLOB (via += or append) now adds the string/character as a UTF-8 encoded byte stream.

    ๐Ÿ†• New features

    • A debugging interface is added.
    • A new bin tool, rhai-dbg (aka The Rhai Debugger), is added to showcase the debugging interface.
    • ๐Ÿ“ฆ A new package, DebuggingPackage, is added which contains the back_trace function to get the current call stack anywhere in a script.
    • Engine::set_fail_on_invalid_map_property is added to control whether to raise an error (new EvalAltResult::ErrorPropertyNotFound) when invalid properties are accessed on object maps.
    • ๐Ÿ‘ Engine::set_allow_shadowing is added to allow/disallow variables shadowing, with new errors EvalAltResult::ErrorVariableExists and ParseErrorType::VariableExists.
    • Engine::on_def_var allows registering a closure which can decide whether a variable definition is allow to continue, during compilation or runtime, or should fail with an error (ParseErrorType::ForbiddenVariable or EvalAltResult::ErrorForbiddenVariable).
    • ๐Ÿ“ฆ A new syntax for defining custom packages is introduced that removes the need to specify the Rhai crate name (internally uses the $crate meta variable).

    โœจ Enhancements

    • 0๏ธโƒฃ Default features for dependencies (such as ahash/std and num-traits/std) are no longer required.
    • The no_module feature now eliminates large sections of code via feature gates.
    • Debug display of AST is improved.
    • NativeCallContext::call_level() is added to give the current nesting level of function calls.
    • A new feature, bin-features, pulls in all the required features for bin tools.
    • AST position display is improved:
      • Expr::start_position is added to give the beginning of the expression (not the operator's position).
      • StmtBlock and Stmt::Block now keep the position of the closing } as well.
    • EvalAltResult::unwrap_inner is added to access the base error inside multiple layers of wrappings (e.g. EvalAltResult::ErrorInFunction).
    • ๐Ÿ“ฆ Yet another new syntax is introduced for def_package! that further simplifies the old syntax.
    • A new method to_blob is added to convert a string into a BLOB as UTF-8 encoded bytes.
    • A new method to_array is added to convert a BLOB into array of integers.

    REPL tool changes

    The REPL bin tool, rhai-rpl, has been enhanced.

    ๐Ÿ— Build changes

    • ๐Ÿ— The rustyline feature is now required in order to build rhai-repl.
    • ๐Ÿ— Therefore, rhai-repl is no longer automatically built when using a simple cargo build with default features.

    Line editor

    • rhai-repl now uses a modified version of rustyline as a line editor with history.
    • Ctrl-Enter can now be used to enter multiple lines without having to attach the \ continuation character the end of each line.
    • ๐Ÿ Bracketed paste is supported, even on Windows (version 10 or above), so pasting code directly into rhai-repl is made much more convenient.

    ๐Ÿ†• New commands

    • strict to turn on/off Strict Variables Mode.
    • โšก๏ธ optimize to turn on/off script optimization.
    • ๐Ÿ–จ history to print lines history.
    • !!, !num, !text and !?text to recall a history line.
    • ๐Ÿ–จ keys to print all key bindings.