Releases: rhaiscript/rhai
Versions 1.23.3 and 1.23.4
Version Control
The ahash crate that Rhai depends on has a breaking change since version 0.8.12 which bumps getrandom to version 0.3, braking certain no-std and wasm builds.
Version 1.23.3: Use this version when building for no-std
Version 1.23.4: This is the main version for std builds.
Bug fixes
- (Fuzzing) Fixed crash when using
..=in arrays, BLOB's, bit-fields and iterators (#1004). - Modules loaded within a
ModuleResolversCollectionnow properly enable access to thescopeetc. - Registered functions for comparison operators with only one operand being a custom type now works properly (thanks
@mkeeter#1003). NativeCallContext::fn_sourcenow correctly returns the source of the function (usuallyNone). The missingNativeCallContext::call_sourceis added to return the source of caller (thanks@FlashSystems#1013).Engine::collect_fn_metadatanow properly includes functions registered into the global namespace (thanks@therealprofand@matthiasbeyer#1017).
Enhancements
build.rsno longer writes to the source tree butOUT_DIRinstead (thanks@matthiasbeyer#1018)CustomTypederive macro now supports generic types (thanks@ProphetOSpam#999). Therhai_codegencrate dependency is bumped to3.0.0or later.CustomTypederive macro now handlesOptionfields (thanks@agersant#1011).Engine::eval_fn_callis added to make a generic function call.Engine::eval_binary_opis added to quickly compare twoDynamicvalues.- Better handling for 32-bit architectures and enhanced safety by replacing casts with
try_from(thanks@therealprof#1009). - The new symbol types
$token$,$inner$, and$raw$can now be used in custom syntax definitions (#1023). Engine::register_custom_syntax_without_look_ahead_rawis added to allow the use of$raw$in custom syntax, which returns the script text character-by-character without processing, by-passing the tokenizer. This in turn allows for parsing arbitrary syntax. (#1022)CallFnOptions::in_all_namespacesis added to allow calling functions in all namespaces, instead of only scripted Rhai functions in theAST.
Version 1.22.0
Bug fixes
- (Fuzzing) An integer-overflow bug from an inclusive range in
get_bitsis fixed (#963). - (Fuzzing) Nested functions marked
privatenow properly cause compilation errors (#993). - Passing function as a function pointer into a function in an imported module now correctly encapsulates the current environment into the generated function pointer (thanks
@dcihlar#976). The same for passing a closure (thanks again,@dcihlar#979). - Revised epsilon-based floating-point comparisons (thanks
@HactarCE#981). - Unneeded optional dependencies are no longer pulled in with features (thanks
@HactarCE#987). Engine::collect_fn_metadatanow properly includes the namespaces of functions in static modules (thanks@therealprofand@elkowar#992).
Enhancements
- Improve display of function call errors by displaying the caller function's source together with line number info (thanks
@rhizoomeand@HactarCE#988). sourceandpositioninNativeCallContextare nowfn_sourceandcall_position. A new methodcall_sourceis added to return the source (if any) of the caller function (thanks@rhizoomeand@HactarCE#989).- The
&&,||and??operators are optimized to allow efficient chaining (#994).
v1.21.0
Bug fixes
- Fixed bug in raw strings (thanks
@benatkin944). get_fn_metadata_listfunction is markedvolatile.no-stdplussyncshould now build correctly (thanksstargazing-dino947).
New Features
- It is possible to create a function pointer (
FnPtr) which binds to a native Rust function or closure viaFnPtr::from_dnandFnPtr::from_dyn_fn. When called in script, the embedded function will be called (thanks@makspll952).
Enhancements
- The methods
call_fn,call_native_fn,call_fn_rawandcall_native_fn_raware added toEvalContext(thanks@rawhuul954). - A new
internalsfunction,Engine::collect_fn_metadata, is added to collect all functions metadata. This is to facilitate better error reporting for missing functions (thankstherealprof945).
v1.20.1
v1.20.0
Bug fixes
- (Fuzzing) An integer-overflow bug from an inclusive range in the bits iterator is fixed.
- (Fuzzing) An integer-underflow bug from an inclusive range is fixed.
- Copy strings if the strings interner is busy instead of panicing (thanks
@irevoire917). - Deserialization of
Scopenow works correctly (thanks@AngelicosPhosphoros918). - Support for
thumbv6mtarget is fixed (thankschxry919)
New features
- Added support for raw strings with the syntax
##..#" ... "#..##(thanks@cellomath908 910).
Enhancements
v1.19.0
Bug fixes
- Variable resolver now correctly resolves variables that are captured in a closure.
NativeCallContext<'_>(with a lifetime parameter) now parses correctly in the#[export_module]macro. This is to allow forrust_2018_idiomslints (thanks@ltabis864).- The
syncfeature now works properly inno-stdbuilds (thanks@misssonder874). - More data-race conditions are caught and returned as errors instead of panicking.
- Missing
minandmaxfunctions where both operands are floats orDecimalare added. - Fixed stack overflow when calling closures recursively (thanks
@MageWeiG880). Engine::call_fnandEngine::call_fn_with_optionsnow correctly use theAST'ssourcefield.- (Fuzzing) Fixed crash when using
..=in strings. - (Fuzzing) A recursive stack-overflow bug in
Dynamic::is_hashableis fixed.
New features
- The
break,continue,returnandthrowstatements can now follow the??operator to short-circuit operations where the value is(). - A new symbol,
$func$, is added to custom syntax to allow parsing of anonymous functions. - The
filter,drainandretainmethods are added to object maps.
v1.18.0
Starting from this version, we try to put contributors' names on features/enhancements/fixes that they contributed.
We apologize for neglecting to adopt this practice earlier, but late is better than never!
Bug fixes
- The position of an undefined operation call now points to the operator instead of the first operand.
- The
optimizecommand inrhai-replnow works properly and cycles throughNone->Simple->Full. Engine::call_fn_XXXno longer return errors unnecessarily wrapped inEvalAltResult::ErrorInFunctionCall.- Some tests that panic on 32-bit architecture are fixed (thanks
@alexanderkjall#851). - The optimizer no longer goes into an infinite loop when optimizing a
trystatement with an empty body.
Deprecated API's
- The plugin macros
export_fn,register_exported_fn!,set_exported_fn!andset_exported_global_fn!are deprecated because they do not add value over existing direct API's.
New features
- Sub-strings can now be selected from full strings by indexing via ranges, e.g.
s[1..4](thanks@zitsen#845). - Doc-comments are now automatically added to function registrations and custom types via the
CustomTypederive macro (thanks@Itabis#847). - New options
Engine::set_max_strings_internedandEngine::max_strings_internedare added to limit the maximum number of strings interned in theEngine's string interner. - A new advanced callback,
Engine::on_invalid_array_index, is added (gated under theinternalsfeature) to handle access to missing properties in object maps. - A new advanced callback,
Engine::on_missing_map_property, is added (gated under theinternalsfeature) to handle out-of-bound index into arrays.
Enhancements
parse_jsonis also available without themetadataorserdefeature -- it usesEngine::parse_jsonto parse the JSON text (thanks@Mathieu-Lala#840).FuncRegistration::in_global_namespaceandFuncRegistration::in_internal_namespaceare added to avoid pulling inFnNamespace.- Array/BLOB/string iterators are defined also within the
BasicIteratorPackagein addition to the regular array/BLOB/string packages. LexError::Runtimeis added for use withEngine::on_parse_token.- Shared values under
syncare now handled more elegantly -- instead of deadlocking and hanging indefinitely, it spins for a number of tries (waiting one second between each), then errors out.
v1.17.1
v1.17.0
Starting from this version, the official preferred method of registering an API for a custom type is via the #[derive(CustomType)] macro. The old API is still available for types that reside in external crates (and thus cannot implement CustomType).
Starting from this version, the new FuncRegistration API is preferred for registering native Rust functions into a Module. The old API is still available but deprecated.
Starting from this version, fuzzing via Google OSS-Fuzz is used to flush out hidden bugs and edge cases. This should result in higher code quality, better stability and improved security. And indeed, a large number of bugs have been discovered from this and fixed.
Potentially breaking changes
ImmutableStringnow derefs to&strinstead of&SmartString. Normally this should not be a breaking change.- Traits implemented by
ImmutableStringare cleaned up. Normally this should not be a breaking change. EvalContext::new,FloatWrapperandConditionalExprare now gated underinternals.- Previously, Rhai follows Unicode's definition for whitespace, which allows many exotic whitespace characters in scripts. Starting from this version, whitespace follows WhatWG's definition of five ASCII characters (TAB, SPACE, CR, LF and FF), which is the same as Rust. All other Unicode whitespace characters (not inside strings) are not considered whitespace by Rhai. If a script used to contain non-ASCII whitespace characters, it now fails to parse with a syntax error.
New features
#[derive(CustomType)]is now available, driven by procedural macros inrhai_codegen.- A new
FuncRegistrationAPI is added to assist in registering native Rust functions into modules with various settings. Some of the originalModule::set_fn...API is now deprecated. - Functions defined in plugin modules can now be marked as
volatilewhich prevents it from being optimized away even underOptimizationLevel::Full. - Added
Engine::max_functionsandEngine::set_max_functionsto limit the maximum number of functions allowed in a script. This is to guard against DOS attacks -- e.g. a simple closure||(two characters) is a function. Whenmax_functionis exceeded during script compilation, a new parse error,ParseErrorType::TooManyFunctions, is returned. Engine::get_interned_stringis made public instead of gated underinternals.
Deprecated API's
rhai::config::hashing::set_ahash_seed,rhai::config::hashing::get_ahash_seedand theRHAI_AHASH_SEEDenvironment variable are deprecated in favor ofrhai::config::hashing::set_hashing_seed,rhai::config::hashing::get_hashing_seedandRHAI_HASHING_SEED.AST::clear_docis deprecated.- Much of the
Module::update_XXXAPI is deprecated in favor of using theFuncRegistrationAPI. Module::gen_fn_signaturesis deprecated in favor ofModule::gen_fn_signatures_with_mapper.
Fixes to bugs found via fuzzing
- Fixed crash when parsing multi-segment interpolated string longer than maximum.
- Fixed crash when parsing unterminated comment.
- Fixed crash when parsing deeply-nested right-associated operators such as
**. - Fixed crash when parsing combo-chaining expressions such as
(a.b).c. - Fixed crash when calling functions that have
Dynamicparameters with more than 16 parameters. - Fixed crash when indexing into an empty array with negative index.
- Indexing into an array with a negative index that is larger than the length of the array now throws an out-of-bounds error (similar to positive indices) instead of defaulting to the first element.
- Fixed edge-case crash in timestamp functions.
- Fixed crash when indenting a block doc-comment with Unicode multi-byte space characters.
- Fixed improper parsing of numbers with too many decimal points.
- Fixed exponential running time when raising a decimal number to a very large power (> 1 million) -- it now returns an overflow error.
- Shared values that contain reference loops no longer cause a stack overflow when printing.
sleepno longer panics onNaN.switchon ranges now work properly.
Other bug fixes
- Arrays in object maps now serialize to JSON correctly via
to_json()when theserdefeature is not enabled. Engine::format_map_as_jsonnow serializes arrays correctly.Engine::gen_fn_signatures(false)now properly skips functions in the standard library.TypeBuilder::with_namenow properly sets the display-name of the type for use in generating metadata.
Enhancements
- Avoid cloning values unless needed when performing constants propagation in optimization.
- Added
to_intmethod for characters. Token::FloatConstantandToken::DecimalConstantnow carry the original text representation for use in, say, a token mapper.Dynamic::is_fnptris made a public API.Scope::get_value_refandScope::get_value_mutare added.TypeBuilder::with_namenow takes any&strinstead of just&'static str.Engine::gen_fn_signaturesnow formats the function signatures using pretty-print names of custom types.