Rhai - An embedded scripting language for Rust.
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!
optimize
command in rhai-repl
now works properly and cycles through None
->Simple
->Full
.Engine::call_fn_XXX
no longer return errors unnecessarily wrapped in EvalAltResult::ErrorInFunctionCall
.@alexanderkjall
#851).try
statement with an empty body.export_fn
, register_exported_fn!
, set_exported_fn!
and set_exported_global_fn!
are deprecated because they do not add value over existing direct API's.s[1..4]
(thanks @zitsen
#845).CustomType
derive macro (thanks @Itabis
#847).Engine::set_max_strings_interned
and Engine::max_strings_interned
are added to limit the maximum number of strings interned in the Engine
's string interner.Engine::on_invalid_array_index
, is added (gated under the internals
feature) to handle access to missing properties in object maps.Engine::on_missing_map_property
, is added (gated under the internals
feature) to handle out-of-bound index into arrays.parse_json
is also available without the metadata
or serde
feature -- it uses Engine::parse_json
to parse the JSON text (thanks @Mathieu-Lala
#840).FuncRegistration::in_global_namespace
and FuncRegistration::in_internal_namespace
are added to avoid pulling in FnNamespace
.BasicIteratorPackage
in addition to the regular array/BLOB/string packages.LexError::Runtime
is added for use with Engine::on_parse_token
.sync
are 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.This is a bug-fix release that bumps rhai_codegen
version to 2.0.0
to satisfy semver rules.
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.
ImmutableString
now derefs to &str
instead of &SmartString
. Normally this should not be a breaking change.ImmutableString
are cleaned up. Normally this should not be a breaking change.EvalContext::new
, FloatWrapper
and ConditionalExpr
are now gated under internals
.#[derive(CustomType)]
is now available, driven by procedural macros in rhai_codegen
.FuncRegistration
API is added to assist in registering native Rust functions into modules with various settings. Some of the original Module::set_fn...
API is now deprecated.volatile
which prevents it from being optimized away even under OptimizationLevel::Full
.Engine::max_functions
and Engine::set_max_functions
to 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. When max_function
is exceeded during script compilation, a new parse error, ParseErrorType::TooManyFunctions
, is returned.Engine::get_interned_string
is made public instead of gated under internals
.rhai::config::hashing::set_ahash_seed
, rhai::config::hashing::get_ahash_seed
and the RHAI_AHASH_SEED
environment variable are deprecated in favor of rhai::config::hashing::set_hashing_seed
, rhai::config::hashing::get_hashing_seed
and RHAI_HASHING_SEED
.AST::clear_doc
is deprecated.Module::update_XXX
API is deprecated in favor of using the FuncRegistration
API.Module::gen_fn_signatures
is deprecated in favor of Module::gen_fn_signatures_with_mapper
.**
.(a.b).c
.Dynamic
parameters with more than 16 parameters.sleep
no longer panics on NaN
.switch
on ranges now work properly.to_json()
when the serde
feature is not enabled.Engine::format_map_as_json
now serializes arrays correctly.Engine::gen_fn_signatures(false)
now properly skips functions in the standard library.TypeBuilder::with_name
now properly sets the display-name of the type for use in generating metadata.to_int
method for characters.Token::FloatConstant
and Token::DecimalConstant
now carry the original text representation for use in, say, a token mapper.Dynamic::is_fnptr
is made a public API.Scope::get_value_ref
and Scope::get_value_mut
are added.TypeBuilder::with_name
now takes any &str
instead of just &'static str
.Engine::gen_fn_signatures
now formats the function signatures using pretty-print names of custom types.Public fields of VarDefInfo
are marked deprecated but still accessible.
Fixes compilation error when importing multiple modules.
Fixes compilation error when using the serde
feature with metadata
.
This version is a general code cleanup such that it relies less on obscure hacks unless those tricks provide genuine performance benefits. It should make the code base easier to follow for new contributors.
The minimum Rust compiler version is raised to 1.66.0
.
max_operations
, max_array_size
etc.) as well as Engine::ensure_data_size_within_limits
are no longer exported under unchecked
. This should be the correct behavior instead of returning None
or zero.OptimizationLevel
is no longer exported under no_optimize
. Originally it was mapped to ()
under no_optimize
.wasm32-wasi
(or any WASM target other than wasm32-unknown
).this
as the first parameter in a namespace-qualified function call.false
(except for !=
which defaults to true
).max
and min
for integers, strings and characters were missing from the standard library. They are now added.Cargo.toml
to avoid breaking changes in future versions.bitflags
is bumped to version 2.syn
in rhai_codegen
is bumped to version 2.hashbrown
(used in no-std
builds) is bumped to version 0.14.ParseErrorType::MalformedCallExpr
and ParseErrorType::MalformedInExpr
are deprecated and will be removed in the next major version.Module::get_custom_type
is deprecated in favor of Module::get_custom_type_display_by_name
and other new methods.exit
function that terminates script evaluation regardless of where it is called, even inside deeply-nested function calls.Engine::max_variables
and Engine::set_max_variables
to limit the maximum number of variables allowed within a scope at any time. This is to guard against defining a huge number of variables containing large data just beyond individual data size limits. When max_variables
is exceeded a new error, ErrorTooManyVariables
, is returned.zip
function for arrays.on_print
and on_debug
definitions for TypeBuilder
.Module::get_custom_type_raw
. These doc-comments for custom types are also exported in JSON via Engine::gen_fn_metadata_to_json
.once_cell
is used in std
environments instead of the home-brew SusLock
which is removed.?
operator liberally to simplify code. However, this causes the loss of proper line numbers when a test fails, making it difficult to identify the exact location of the failure. This is now fixed by changing to unwrap()
.Vec
because they are not transient and do not appear to improve performance. Using Vec
seems to be yield better performance as it probably enables more compiler optimizations.This is a minor bug-fix release.
Dynamic::deep_scan
is fixed so now it properly scans arrays, object maps and function pointers embedded inside data.garypen
!).this
should now run slightly faster due to a dedicated AST
node ThisPtr
.take
function is added to the standard library to take ownership of any data (replacing with ()
) in order to avoid cloning.Dynamic::take
is added to take ownership of the data (replacing with ()
) in order to avoid cloning.EvalAltResult::ErrorMismatchOutputType
now gives a better name for the requested generic type (e.g. &str
is now &str
and not string
).This new version contains a substantial number of bug fixes for edge cases.
A new syntax is supported to facilitate writing object methods in script.
The code hacks that attempt to optimize branch prediction performance are removed because benchmarks do not show any material speed improvements.
is_shared
is a reserved keyword and is now handled properly (e.g. it cannot be the target of a function pointer).optimize_ast
with constants now works correctly for closures. Previously the hidden Share
nodes are not removed and causes variable-not-found errors during runtime if the constants are not available in the scope.(v[0].func()).prop
now parse correctly.const X = 1; const X = 1 + 1 + 1; X
now evaluates to 3 instead of 0).thumbv6m-none-eabi
target (e.g. Raspberry Pi Pico) now completes successfully. Dependency to no-std-compat
is now pointed to the latest repo instead of crates.io
.this
pointer for a particular script-defined function so that it is called only when the this
pointer contains the specified type.is_def_fn
is extended to support checking for typed methods, with syntax is_def_fn(this_type, fn_name, arity)
Dynamic::take
is added as a short-cut for std::mem::take(&mut value)
.Engine::is_symbol_disabled
is added to test whether a particular keyword/symbol is disabled.Dynamic
value containing custom types or shared values back into another Dynamic
(essentially a straight cloned copy).