v1.5.0
This version adds a debugging interface, which can be used to integrate a debugger.
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
tryblocks 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
importstatement, theexportstatement no longer exports multiple variables. - Appending a BLOB to a string (via
+,+=,appendor string interpolation) now treats the BLOB as a UTF-8 encoded string. - Appending a string/character to a BLOB (via
+=orappend) 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 theback_tracefunction to get the current call stack anywhere in a script. Engine::set_fail_on_invalid_map_propertyis added to control whether to raise an error (newEvalAltResult::ErrorPropertyNotFound) when invalid properties are accessed on object maps.Engine::set_allow_shadowingis added to allow/disallow variables shadowing, with new errorsEvalAltResult::ErrorVariableExistsandParseErrorType::VariableExists.Engine::on_def_varallows 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::ForbiddenVariableorEvalAltResult::ErrorForbiddenVariable).- A new syntax for defining custom packages is introduced that removes the need to specify the Rhai crate name (internally uses the
$cratemeta variable).
Enhancements
- Default features for dependencies (such as
ahash/stdandnum-traits/std) are no longer required. - The
no_modulefeature now eliminates large sections of code via feature gates. - Debug display of
ASTis 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 forbintools. ASTposition display is improved:Expr::start_positionis added to give the beginning of the expression (not the operator's position).StmtBlockandStmt::Blocknow keep the position of the closing}as well.
EvalAltResult::unwrap_inneris 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_blobis added to convert a string into a BLOB as UTF-8 encoded bytes. - A new method
to_arrayis added to convert a BLOB into array of integers.
REPL tool changes
The REPL bin tool, rhai-rpl, has been enhanced.
Build changes
- The
rustylinefeature is now required in order to buildrhai-repl. - Therefore,
rhai-replis no longer automatically built when using a simplecargo buildwith default features.
Line editor
rhai-replnow uses a modified version ofrustylineas 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-replis made much more convenient.
New commands
strictto turn on/off Strict Variables Mode.optimizeto turn on/off script optimization.historyto print lines history.!!,!num,!text and!?text to recall a history line.keysto print all key bindings.