Releases: rhaiscript/rhai
v1.7.0
This release is primarily minor functionality and API enhancements.
Bug fixes
- Compound assignments now work properly with indexers.
- Cloning a
Scope
no longer turns all constants to mutable.
Script-breaking changes
- Strict Variables Mode no longer returns an error when an undeclared variable matches a variable/constant in the provided external
Scope
.
Potentially breaking API changes
- The
Engine::on_var
andEngine::on_parse_token
API's are now marked unstable/volatile. - The closures passed to
Engine::on_var
,Engine::on_def_var
andEngine::register_debugger
takeEvalContext
instead of&EvalContext
or&mut EvalContext
. - The following enum's are marked
non_exhaustive
:AccessMode
,FnAccess
,FnNamespace
,FnMetadata
,OptimizationLevel
New API
Module::eval_ast_as_new_raw
is made public as a low-level API.format_map_as_json
is provided globally, which is the same asto_json
for object maps.Engine::call_fn_raw_raw
is added to add speed to repeated function calls.Engine::eval_statements_raw
is added to evaluate a sequence of statements.
New features
- A custom state is provided that is persistent during the entire evaluation run. This custom state is a
Dynamic
, which can hold any data, and can be accessed by the host viaEvalContext::tag
,EvalContext::tag_mut
,NativeCallContext::tag
andGlobalRuntimeState.tag
.
Enhancements
- Improper
switch
case condition syntax is now caught at parse time. Engine::parse_json
now natively handles nested JSON inputs (using a token remap filter) without needing to replace{
with#{
.to_json
is added to object maps to cheaply convert it to JSON format (()
is mapped tonull
, all other data types must be supported by JSON)FileModuleResolver
now accepts a customScope
to provide constants for optimization.- New variants,
Start
andEnd
, are added toDebuggerEvent
triggered at the start/end of script evaluation.
v1.6.1
This is a minor bug-fix release
Bug fixes
- Functions with
Dynamic
parameters now work in qualified calls fromimport
ed modules. rhai-repl
now compiles with the new patch version ofrustyline
.rhai_codegen
dependency is now explicitly1.4
or higher.
Script-breaking changes
split
now splits a string by whitespaces instead of splitting it into individual characters. This is more in line with common practices.- A new function
to_chars
for strings is added to split the string into individual characters.
Enhancements
- Strings are now directly iterable (via
for .. in
) yielding individual characters.
v1.6.0
This version, in particular, fixes a plugin macro hygiene error for the nightly compiler:
error[E0425]: cannot find value `args` in this scope
rhai_codegen
needs to be version 1.4.0
. Run cargo update
if it is a lower version.
Compiler version
- Minimum compiler version is now
1.57
due tosmartstring
dependency.
Bug fixes
- Fixed macro hygiene error with nightly compiler.
- Invalid property or method access such as
a.b::c.d
ora.b::func()
no longer panics but properly returns a syntax error. Scope::is_constant
now returns the correct value.- Exporting a variable that contains a local function pointer (including anonymous function or closure) now raises a runtime error.
- Full optimization is now skipped for method calls.
New features
- Type aliases in plugin modules are now used as friendly names for custom types. This makes plugin modules more self-contained when they are used to define a custom type's API.
Enhancements
- Variable definitions are optimized so that shadowed variables are reused as much as possible to reduce memory consumption.
FnAccess
andFnNamespace
now implementOrd
andPartialOrd
.- The
event_handler_map
example is enhanced to prevent shadowing of the state object map. - Separation of constants in function calls is removed as its performance benefit is dubious.
- A function
sleep
is added to block the current thread by a specified number of seconds. Scope::set_alias
is added to export a variable under a particular alias name.starts_with
andends_with
are added for strings.- Variables in modules registered via
register_global_module
can now be accessed in the global namespace. Dynamic::into_read_only
is added to convert aDynamic
value into constant.Module
now holds a collection of custom types with an API.
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
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
- 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.
v1.4.1
This is primarily a bug-fix version which fixes a large number of bugs.
Bug fixes
- Expressions such as
x = x + 1
no longer panics. - Padding arrays with another array via
pad
no longer loops indefinitely. chop
for arrays and BLOB's now works properly.set_bit
for bit-flags with negative index now works correctly.- Misnamed
params
fieldname
in the JSON output ofEngine::gen_fn_metadata_to_json
is fixed (was incorrectly namedtype
). - Fixes a potential
unsafe
violation infor
loop. - Missing
to_hex
,to_octal
andto_binary
fori128
andu128
are added. remove
for arrays and BLOB's now treat negative index correctly.parse_int
now works properly for negative numbers.Engine::gen_fn_signatures
now generates signatures for external packages registered viaEngine::register_global_module
.\r\n
pairs are now recognized correctly for doc-comments.
Enhancements
- Formatting of return types in functions metadata info is improved.
- Use
SmartString
forScope
variable names and removeunsafe
lifetime casting. - Functions in the standard library now have doc-comments (which can be obtained via
Engine::gen_fn_metadata_to_json
). get
andset
methods are added to arrays, BLOB's, object maps and strings.
v1.4.0
This version adds support for integer ranges via the ..
and ..=
operators.
Many standard API's are extended with range parameters where appropriate.
A number of usability improvements simplify integration with Rust.
Script-breaking changes
is
is (pun intended) now a reserved keyword to prepare for possible future type checking expressions (e.g.x is "string"
).
Breaking changes
LogicPackage
is removed fromCorePackage
.- Bit-field functions are moved into a new
BitFieldPackage
(used to be inLogicPackage
) which makes more sense.
Bug fixes
- Custom syntax now works properly inside binary expressions and with method calls.
- Hex numbers with the high-bit set now parse correctly into negative integer numbers.
- Constructing a literal array or object map now checks for size limits for each item instead of at the very end when it is already too late.
- Non-
INT
integer types are now treated exactly as custom types underonly_i64
andonly_i32
. - Calling
pad
on an array now checks for total size over limit after each item added.
New features
- Added support for integer ranges via the
..
and..=
operators. - Added
EvalAltResult::ErrorCustomSyntax
to catch errors in custom syntax, which should not happen unless anAST
is compiled on oneEngine
but evaluated on another unrelatedEngine
.
Enhancements
BLOB
's are refined to display in a more compact hex format.- A new syntax is introduced for
def_package!
that will replace the old syntax in future versions. - Added
NativeCallContext::call_fn
to easily call a function. - Doc-comments on plugin module functions are extracted into the functions' metadata.
Deprecated API's
Expression::get_variable_name
is deprecated in favor of the newExpression::get_string_value
.- The old syntax of
def_package!
is deprecated in favor of the new syntax.
v1.3.0
Version 1.3.0
released to crates.io
.
This version adds native support for BLOB
's (byte arrays), as well as a number of configuration settings to fine-tun language features.
Compiler requirement
- Minimum compiler version is now 1.51.
Bug fixes
from_dynamic
now supports deserializingOption
.
New features
BLOB
(essentially a byte array) is added as a supported primitive value type parallel to arrays.- New options for
Engine
which allows disablingif
-expressions,switch
-expressions, statement expressions, anonymous functions and/or looping (i.e.while
,loop
,do
andfor
statements):Engine::set_allow_if_expression
Engine::set_allow_switch_expression
Engine::set_allow_statement_expression
Engine::set_allow_anonymous_fn
Engine::set_allow_looping
- New strict variables mode for
Engine
(enabled viaEngine::set_strict_variables
) to throw parse errors on undefined variable usage. Two new parse error variants,ParseErrorType::VariableNotFound
andParseErrorType::ModuleNotFound
, are added.
Enhancements
- Two double quotes (
""
) in a string literal now maps to"
; two back-ticks (``
) in a literal string now maps to`
. - Added
Engine::register_type_with_name_raw
to register a custom type based on a fully-qualified type path. - Added
into_array
andinto_typed_array
forDynamic
. - Added
FnPtr::call
andFnPtr::call_within_context
to simplify calling a function pointer. - A function's hashes are included in its JSON metadata to assist in debugging. Each function's
baseHash
field in the JSON object should map directly to the pre-calculated hash in the function call. Expression
now derefs toExpr
.
Deprecated and Gated API's
NativeCallContext::new
is deprecated because it is simpler to call a function pointer viaFnPtr::call
.AST::merge_filtered
andAST::combine_filtered
are no longer exported underno_function
.AST::new
andAST::new_with_source
are moved underinternals
.FnPtr::call_dynamic
is deprecated in favor ofFnPtr::call_raw
.
v1.2.1
v1.2.0
Version 1.2.0
released to crates.io
.
Bug fixes with breaking script changes
- As originally intended, function calls with a bang (
!
) now operates directly on the caller's scope, allowing variables inside the scope to be mutated. - As originally intended,
Engine::XXX_with_scope
API's now properly propagate constants within the provided scope also to functions in the script. - Printing of integral floating-point numbers is fixed (used to only prints
0.0
). func!()
calls now work properly underno_closure
.- Fixed parsing of unary negation such that expressions like
if foo { ... } -x
parses correctly.
New features
#[cfg(...)]
attributes can now be put directly on plugin functions or function defined in a plugin module.- A custom syntax parser can now return a symbol starting with
$$
to inform the implementation function which syntax variant was actually parsed. AST::iter_literal_variables
is added to extract all top-level literal constant/variable definitions from a script without running it.Engine::call_fn_dynamic
is deprecated andEngine::call_fn_raw
is added which allows keeping new variables in the custom scope.
Enhancements
- Array methods now avoid cloning as much as possible (although most predicates will involve cloning anyway if passed a closure).
- Array methods that take function pointers (e.g. closures) now optionally take the function name as a string.
- Array adds the
dedup
method. - Array adds a
sort
method with no parameters which sorts homogeneous arrays of built-in comparable types (e.g.INT
). - Inlining is disabled for error-path functions because errors are exceptional and scripts usually fail completely when an error is encountered.
- The
optimize
module is completely eliminated underno_optimize
, which should yield smaller code size. NativeCallContext::position
is added to return the position of the function call.Scope::clone_visible
is added that copies only the last instance of each variable, omitting all shadowed variables.
Deprecated API's
NativeCallContext::call_fn_dynamic_raw
is deprecated andNativeCallContext::call_fn_raw
is added.From<EvalAltResult>
forResult<T, Box<EvalAltResult>>
is deprecated so it will no longer be possible to doEvalAltResult::ErrorXXXXX.into()
to convert to aResult
; instead,Err(EvalAltResult:ErrorXXXXX.into())
must be used. Code is clearer if errors are explicitly wrapped inErr
.
v1.1.2
This release fixes a number of bugs:
0.0
now prints correctly (used to print0e0
).- Unary operators are now properly recognized as an expression statement.
- The global namespace is now searched before packages, which is the correct behavior.
A regression in string operations via the +
operator is also reversed.