Releases: rhaiscript/rhai
v.0.19.9
This version fixes a bug introduced in 0.19.8
which breaks property access
within closures.
It also removes the confusing differences between packages and modules
by unifying the terminology and API under the global umbrella of modules.
Version 0.19.9
released to crates.io
.
Bug fixes
- Fix bug when accessing properties in closures.
- Fix bug when accessing a deep index with a function call.
- Fix bug that sometimes allow assigning to an invalid l-value.
- Fix off-by-one error with
Engine::set_max_call_levels
.
Breaking changes
Engine::load_package
is renamedEngine::register_global_module
and now must explicitly pass a shared [Module
].Engine::register_module
is renamedEngine::register_static_module
and now must explicitly pass a shared [Module
].Package::get
is renamedPackage::as_shared_module
.Engine::set_module_resolver
now takes a straight module resolver instead of anOption
. To disable module resolving, use the newDummyModuleResolver
.
Enhancements
Scope
is nowClone + Hash
.Engine::register_static_module
now supports sub-module paths (e.g.foo::bar::baz
).Engine::register_custom_operator
now accepts reserved symbols.Engine::register_custom_operator
now returns an error if given a precedence of zero.- The examples
repl
andrhai_runner
are moved intobin
and renamedrhai-repl
andrhai-run
respectively.
v.0.19.8
This version makes it easier to generate documentation for a Rhai code base.
Each function defined in an AST
can optionally attach doc-comments (which, as in Rust,
are comments prefixed by either ///
or /**
). Doc-comments allow third-party tools to
automatically generate documentation for functions defined in a Rhai script.
A new API, Engine::gen_fn_metadata_to_json
and Engine::gen_fn_metadata_with_ast_to_json
,
paired with the new metadata
feature, exports the full list of functions metadata
(including those in an AST
) as a JSON document.
There are also a sizable number of bug fixes.
Version 0.19.8
released to crates.io
.
Bug fixes
- Unary prefix operators
-
,+
and!
now bind correctly when applied to an expression. Previously,-x.len
is parsed as(-x).len
which is obviously counter-intuitive. - Indexing of namespace-qualified variables now work properly, such as
path::to::var[x]
. - Constants are no longer propagated by the optimizer if shadowed by a non-constant variable.
- A constant passed as the
this
parameter to Rhai functions now throws an error if assigned to. - Generic type parameter of
Engine::register_iterator
isIntoIterator
instead ofIterator
. - Fixes parsing of block comments ending with
**/
or inner blocks starting with//*
.
Breaking changes
Engine::on_progress
now takesu64
instead of&u64
.- The closure for
Engine::on_debug
now takes two additional parameters:source: Option<&str>
andpos: Position
. AST::iter_functions
now returnsScriptFnMetadata
.- The parser function passed to
Engine::register_custom_syntax_raw
now takes an additional parameter containing the look-ahead symbol.
New features
AST::iter_functions
now returnsScriptFnMetadata
which includes, among others, doc-comments for functions prefixed by///
or/**
.- Doc-comments can be enabled/disabled with the new
Engine::set_doc_comments
method. - A new feature
metadata
is added that pulls inserde_json
and enablesEngine::gen_fn_metadata_to_json
andEngine::gen_fn_metadata_with_ast_to_json
which exports the full list of functions metadata (including those inside anAST
) in JSON format. Engine::on_debug
provides two additional parameters:source: Option<&str>
andpos: Position
, containing the current source (if any) and position of thedebug
statement.NativeCallContext
andEvalContext
both exposesource()
which returns the current source, if any.
Enhancements
- A functions lookup cache is added to make function call resolution faster.
- Capturing a constant variable in a closure is now supported, with no cloning.
- A look-ahead symbol is provided to custom syntax parsers, which can be used to parse variable-length symbol streams.
v.0.19.7
This is a minor bug-fix release with a few small enhancements.
Version 0.19.7
released to crates.io
.
Bug fixes
- Fixes compilation errors with certain feature flag combinations.
Enhancements
- Property getters/setters and indexers defined in a plugin module are by default
#[rhai_fn(global)]
. to_debug
is a new standard function for converting a value into debug format.- Arrays and object maps now print values using
to_debug
(if available).
v.0.19.6
This version adds the switch
statement.
It also allows exposing selected module functions (usually methods) to the global namespace.
This is very convenient when encapsulating the API of a custom Rust type into a module while having methods
and iterators registered on the custom type work normally.
A new gen_fn_signatures
API enables enumerating the registered functions of an Engine
for documentation purposes.
It also prepares the way for a future reflection API.
Release 0.19.6
released to crates.io
.
Bug fixes
- Custom syntax that introduces a shadowing variable now works properly.
Breaking changes
Module::set_fn
,Module::set_raw_fn
andModule::set_fn_XXX_mut
all take an additional parameter ofFnNamespace
.Module::set_fn
takes a further parameter with a list of parameter names/types plus the function return type, if any.Module::get_sub_module_mut
is removed.begin
,end
,unless
are now reserved keywords.EvalPackage
is removed in favor ofEngine::disable_symbol
.
New features
- New
switch
statement. - New
do ... while
anddo ... until
statements. - New
Engine::gen_fn_signatures
,Module::gen_fn_signatures
andPackagesCollection::gen_fn_signatures
to generate a list of signatures for functions registered. - New
Engine::register_module
to register a module as a sub-module in the global namespace. - New
set_exported_global_fn!
macro to register a plugin function and expose it to the global namespace. Module::set_fn_XXX_mut
can expose a module function to the global namespace. This is convenient when registering an API for a custom type.Module::set_getter_fn
,Module::set_setter_fn
,Module::set_indexer_get_fn
,Module::set_indexer_set_fn
all expose the function to the global namespace by default. This is convenient when registering an API for a custom type.- New
Module::update_fn_metadata
to update a module function's parameter names and types. - New
#[rhai_fn(global)]
and#[rhai_fn(internal)]
attributes to determine whether a function defined in a plugin module should be exposed to the global namespace. This is convenient when defining an API for a custom type. - New
get_fn_metadata_list
to get the metadata of all script-defined functions in scope.
Enhancements
- New constants under
Dynamic
includingUNIT
,TRUE
,FALSE
,ZERO
,ONE
etc. - Floating-point numbers ending with a decimal point without a trailing
0
are supported.
v.0.19.5
This version fixes a bug that prevents compilation with the internals
feature.
It also speeds up importing modules.
Version 0.19.5
released to crates.io
.
Bug fixes
- Fixes compilation error when using the
internals
feature. Bug introduced in0.19.4
. - Importing script files recursively no longer panics.
Breaking changes
- Modules imported at global level can now be accessed in functions.
ModuleResolver::resolve
now returnsShared<Module>
for better resources sharing when loading modules.ParseErrorType::DuplicatedExport
is removed as multipleexport
's are now allowed.
Enhancements
- Modules imported via
import
statements at global level can now be used in functions. There is no longer any need to re-import
the modules at the beginning of each function block. - Modules imported via
import
statements are encapsulated into theAST
when loading a module from a script file. export
keyword can now be tagged ontolet
andconst
statements as a short-hand, e.g.:export let x = 42;
- Variables can now be
export
-ed multiple times under different names. index_of
,==
and!=
are defined for arrays.==
and!=
are defined for object maps.
v.0.19.4
Note: Timed this to USA presidential election day just for kicks...
This version basically cleans up the code structure in preparation for a potential 1.0
release in the future.
Most scripts should see a material speed increase.
This version also adds a low-level API for more flexibility when defining custom syntax.
Version 0.19.4
released to crates.io
.
Bug fixes
- Fixes
Send + Sync
forEvalAltResult
under thesync
feature. Bug introduced with0.19.3
.
Breaking changes
- Custom syntax can no longer start with a keyword (even a reserved one), even if it has been disabled. That is to avoid breaking scripts later when the keyword is no longer disabled.
Changes to Error Handling
EvalAltResult::ErrorAssignmentToUnknownLHS
is moved toParseError::AssignmentToInvalidLHS
.ParseError::AssignmentToCopy
is removed.EvalAltResult::ErrorDataTooLarge
is simplified.Engine::on_progress
closure signature now returnsOption<Dynamic>
with the termination value passed on toEvalAltResult::ErrorTerminated
.ParseErrorType::BadInput
now wraps aLexError
instead of a text string.
New features
f32_float
feature to setFLOAT
tof32
.- Low-level API for custom syntax allowing more flexibility in designing the syntax.
Module::fill_with
to poly-fill a module with another.- Scripts terminated via
Engine::on_progress
can now pass on a value as a termination token.
Enhancements
- Essential AST structures like
Expr
andStmt
are packed into smaller sizes (16 bytes and 32 bytes on 64-bit), stored inline for more cache friendliness, and de-Box
ed as much as possible. Scope
is optimized for cache friendliness.
v.0.19.3
This version adds the try
... catch
statement to catch errors and exceptions. It also streamlines some of the advanced API's.
Version 0.19.3
released to crates.io
.
Breaking changes
EvalAltResult::ErrorReadingScriptFile
is removed in favor of the newEvalAltResult::ErrorSystem
.EvalAltResult::ErrorLoopBreak
is renamed toEvalAltResult::LoopBreak
.Engine::register_raw_fn
andFnPtr::call_dynamic
function signatures have changed.- Callback signatures to
Engine::on_var
andEngine::register_custom_syntax
have changed. EvalAltResult::ErrorRuntime
now wraps aDynamic
instead of a string.- Default call stack depth for
debug
builds is reduced to 8 (from 12) because it keeps overflowing the stack in GitHub CI! - Keyword
thread
is reserved.
New features
- The plugins system is enhanced to support functions taking a
NativeCallContext
as the first parameter. throw
statement can now throw any value instead of just text strings.- New
try
...catch
statement to catch exceptions.
Enhancements
- Calling
eval
orFn
in method-call style, which is an error, is now caught during parsing. func!()
call style is valid even underno_closure
feature.
v.0.19.2
This version adds a variable resolver with the ability to short-circuit variable access,
plus a whole bunch of array methods.
Version 0.19.2
released to crates.io
.
Breaking changes
AST::iter_functions
now returns an iterator instead of taking a closure.Module::get_script_function_by_signature
renamed toModule::get_script_fn
and returns&<Shared<ScriptFnDef>>
.Module::num_fn
,Module::num_var
andModule::num_iter
are removed and merged intoModule::count
.- The
merge_namespaces
parameter toModule::eval_ast_as_new
is removed and now defaults totrue
. GlobalFileModuleResolver
is removed because its performance gain over theFileModuleResolver
is no longer very significant.- The following
EvalAltResult
variants are removed and merged intoEvalAltResult::ErrorMismatchDataType
:ErrorCharMismatch
,ErrorNumericIndexExpr
,ErrorStringIndexExpr
,ErrorImportExpr
,ErrorLogicGuard
,ErrorBooleanArgMismatch
Scope::iter_raw
returns an iterator with an additional field indicating whether the variable is constant or not.rhai::ser
andrhai::de
namespaces are merged intorhai::serde
.- New reserved symbols:
++
,--
,..
,...
. - Callback signature for custom syntax implementation function is changed to allow for more flexibility.
- Default call stack depth for
debug
builds is reduced to 12 (from 16). - Precedence for
~
is raised, whilein
is moved below logic comparison operators.
New features
- New
Engine::on_var
to register a variable resolver. const
statements can now take any expression (or none at all) instead of only constant values.OptimizationLevel::Simple
now eagerly evaluates built-in binary operators of primary types (if not overloaded).is_def_var()
to detect if variable is defined, andis_def_fn()
to detect if script function is defined.Dynamic::from(&str)
now constructs aDynamic
with a copy of the string as value.AST::combine
andAST::combine_filtered
allows combining twoAST
's without creating a new one.map
,filter
,reduce
,reduce_rev
,some
,all
,extract
,splice
,chop
andsort
functions for arrays.- New
Module::set_iterable
andModule::set_iterator
to define type iterators more easily.Engine::register_iterator
is changed to use the simpler version.
Enhancements
- Many one-liners and few-liners are now marked
#[inline]
or[inline(always)]
, just in case it helps when LTO is not turned on.
v.0.19.0
The major new feature for this version is Plugins support, powered by procedural macros.
Plugins make it extremely easy to develop and register Rust functions with an Engine
.
Version 0.19.0 released to crates.io
.
Bug fixes
if
statement with an emptytrue
block would not evaluate thefalse
block. This is now fixed.- Fixes a bug in
Module::set_fn_4_mut
. - Module API's now properly handle
&str
andString
parameters. - Indexers are available under
no_object
. - Registered operator-assignment functions (e.g.
+=
) now work correctly.
Breaking changes
Engine::register_set_result
andEngine::register_indexer_set_result
now take a function that returnsResult<(), Box<EvalAltResult>>
.Engine::register_indexer_XXX
andModule::set_indexer_XXX
panic when the type isArray
,Map
orString
.EvalAltResult
has a new variantErrorInModule
which holds errors when loading an external module.Module::eval_ast_as_new
now takes an extra boolean parameter, indicating whether to encapsulate the entire module into a separate namespace.- Functions in
FileModuleResolver
loaded modules now can cross-call each other in addition to functions in the global namespace. For the old behavior, useMergingFileModuleResolver
instead. - New
EvalAltResult::ErrorInModule
variant capturing errors when loading a module from a script file.
New features
- Plugins support via procedural macros.
- Scripted functions are allowed in packages.
parse_int
andparse_float
functions for parsing numbers;split
function for splitting strings.AST::iter_functions
andModule::iter_script_fn_info
to iterate functions.- Functions iteration functions for
AST
andModule
now takeFnMut
instead ofFn
. - New
FileModuleResolver
that encapsulates the entireAST
of the module script, allowing function cross-calling. The old version is renamedMergingFileModuleResolver
. +
and-
operators for timestamps to increment/decrement by seconds.