Skip to content

v.0.19.8

Compare
Choose a tag to compare
@schungx schungx released this 22 Dec 07:39
714b8de

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 is IntoIterator instead of Iterator.
  • Fixes parsing of block comments ending with **/ or inner blocks starting with //*.

Breaking changes

  • Engine::on_progress now takes u64 instead of &u64.
  • The closure for Engine::on_debug now takes two additional parameters: source: Option<&str> and pos: Position.
  • AST::iter_functions now returns ScriptFnMetadata.
  • 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 returns ScriptFnMetadata 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 in serde_json and enables Engine::gen_fn_metadata_to_json and Engine::gen_fn_metadata_with_ast_to_json which exports the full list of functions metadata (including those inside an AST) in JSON format.
  • Engine::on_debug provides two additional parameters: source: Option<&str> and pos: Position, containing the current source (if any) and position of the debug statement.
  • NativeCallContext and EvalContext both expose source() 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.