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 ofrustyline
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, theexport
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
+=
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_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 (newEvalAltResult::ErrorPropertyNotFound
) when invalid properties are accessed on object maps.- ๐
Engine::set_allow_shadowing
is added to allow/disallow variables shadowing, with new errorsEvalAltResult::ErrorVariableExists
andParseErrorType::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
orEvalAltResult::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
andnum-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 forbin
tools. AST
position display is improved:Expr::start_position
is added to give the beginning of the expression (not the operator's position).StmtBlock
andStmt::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 buildrhai-repl
. - ๐ Therefore,
rhai-repl
is no longer automatically built when using a simplecargo build
with default features.
Line editor
rhai-repl
now uses a modified version ofrustyline
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.
- ๐ฏ In