Skip to content

Commit

Permalink
Merge pull request #550 from schungx/master
Browse files Browse the repository at this point in the history
Release 1.6.1
  • Loading branch information
schungx committed Apr 11, 2022
2 parents 82cc4b5 + a33e3ba commit 1616541
Show file tree
Hide file tree
Showing 26 changed files with 437 additions and 238 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
Rhai Release Notes
==================

Version 1.6.1
=============

Bug fixes
---------

* Functions with `Dynamic` parameters now work in qualified calls from `import`ed modules.
* `rhai-repl` now compiles with the new patch version of `rustyline`.

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.


Version 1.6.0
=============

This version, in particular, fixes a plugin macro hygiene error for the nightly compiler:

```text
error[E0425]: cannot find value `args` in this scope
```

Compiler version
----------------

Expand All @@ -12,6 +39,7 @@ Compiler version
Bug fixes
---------

* Fixed macro hygiene error with nightly compiler.
* Invalid property or method access such as `a.b::c.d` or `a.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.
Expand Down
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "codegen"]

[package]
name = "rhai"
version = "1.6.0"
version = "1.6.1"
rust-version = "1.57"
edition = "2018"
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung", "jhwgh1968"]
Expand All @@ -22,7 +22,7 @@ ahash = { version = "0.7", default-features = false }
num-traits = { version = "0.2", default-features = false }
bitflags = { version = "1", default-features = false }
smartstring = { version = "1", default-features = false }
rhai_codegen = { version = "1.2", path = "codegen", default-features = false }
rhai_codegen = { version = "1.4", path = "codegen", default-features = false }

no-std-compat = { version = "0.4", default-features = false, features = ["alloc"], optional = true }
libm = { version = "0.2", default-features = false, optional = true }
Expand All @@ -31,9 +31,7 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
serde_json = { version = "1.0", default-features = false, features = ["alloc"], optional = true }
unicode-xid = { version = "0.2", default-features = false, optional = true }
rust_decimal = { version = "1.16", default-features = false, features = ["maths"], optional = true }
# notice that a custom modified version of `rustyline` is used which supports bracketed paste on Windows
# this can be moved to the official version when bracketed paste is added
rustyline = { version = "9", optional = true, git = "https://github.com/schungx/rustyline" }
rustyline = { version = "9", optional = true }

[dev-dependencies]
serde_bytes = "0.11"
Expand Down Expand Up @@ -91,3 +89,8 @@ instant = { version = "0.1.10" } # WASM implementation of std::time::Instant

[package.metadata.docs.rs]
features = ["metadata", "serde", "internals", "decimal", "debugging"]

[patch.crates-io]
# Notice that a custom modified version of `rustyline` is used which supports bracketed paste on Windows.
# This can be moved to the official version when bracketed paste is added.
rustyline = { git = "https://github.com/schungx/rustyline" }
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rhai - Embedded Scripting for Rust
=================================
==================================

![GitHub last commit](https://img.shields.io/github/last-commit/rhaiscript/rhai?logo=github)
[![Build Status](https://github.com/rhaiscript/rhai/workflows/Build/badge.svg)](https://github.com/rhaiscript/rhai/actions)
Expand All @@ -11,6 +11,7 @@ Rhai - Embedded Scripting for Rust
[![VS Code plugin installs](https://img.shields.io/visual-studio-marketplace/i/rhaiscript.vscode-rhai?logo=visual-studio-code&label=vs%20code)](https://marketplace.visualstudio.com/items?itemName=rhaiscript.vscode-rhai)
[![Sublime Text package downloads](https://img.shields.io/packagecontrol/dt/Rhai.svg?logo=sublime-text&label=sublime%20text)](https://packagecontrol.io/packages/Rhai)
[![Discord Chat](https://img.shields.io/discord/767611025456889857.svg?logo=discord&label=discord)](https://discord.gg/HquqbYFcZ9)
[![Forum](https://img.shields.io/discourse/topics?server=https%3A%2F%2Frhai.discourse.group&logo=discourse&label=forum)](https://rhai.discourse.group/)
[![Zulip Chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg?logo=zulip)](https://rhaiscript.zulipchat.com)
[![Reddit Channel](https://img.shields.io/reddit/subreddit-subscribers/Rhai?logo=reddit&label=reddit)](https://www.reddit.com/r/Rhai)

Expand Down Expand Up @@ -65,7 +66,7 @@ Protected against attacks


For those who actually want their own language
---------------------------------------------
----------------------------------------------

* Use as a [DSL](https://rhai.rs/book/engine/dsl.html).
* Disable certain [language features](https://rhai.rs/book/engine/options.html#language-features) such as [looping](https://rhai.rs/book/engine/disable-looping.html).
Expand Down
4 changes: 4 additions & 0 deletions codegen/ui_tests/non_clonable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ note: required by a bound in `rhai::Dynamic::cast`
| pub fn cast<T: Any + Clone>(self) -> T {
| ^^^^^ required by this bound in `rhai::Dynamic::cast`
= note: this error originates in the attribute macro `export_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `NonClonable` with `#[derive(Clone)]`
|
3 | #[derive(Clone)]
|
4 changes: 4 additions & 0 deletions codegen/ui_tests/non_clonable_second.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ note: required by a bound in `rhai::Dynamic::cast`
| pub fn cast<T: Any + Clone>(self) -> T {
| ^^^^^ required by this bound in `rhai::Dynamic::cast`
= note: this error originates in the attribute macro `export_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `NonClonable` with `#[derive(Clone)]`
|
3 | #[derive(Clone)]
|
4 changes: 4 additions & 0 deletions codegen/ui_tests/rhai_fn_non_clonable_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ note: required by a bound in `rhai::Dynamic::from`
| pub fn from<T: Variant + Clone>(value: T) -> Self {
| ^^^^^ required by this bound in `rhai::Dynamic::from`
= note: this error originates in the attribute macro `export_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `NonClonable` with `#[derive(Clone)]`
|
3 | #[derive(Clone)]
|
4 changes: 4 additions & 0 deletions codegen/ui_tests/rhai_mod_non_clonable_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ note: required by a bound in `rhai::Dynamic::from`
| pub fn from<T: Variant + Clone>(value: T) -> Self {
| ^^^^^ required by this bound in `rhai::Dynamic::from`
= note: this error originates in the attribute macro `export_module` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `NonClonable` with `#[derive(Clone)]`
|
3 | #[derive(Clone)]
|
36 changes: 36 additions & 0 deletions src/api/type_names.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::packages::iter_basic::{BitRange, CharsStream, StepRange};
use crate::{
Engine, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, Position, RhaiError, ERR,
};
Expand Down Expand Up @@ -65,6 +66,41 @@ fn map_std_type_name(name: &str, shorthands: bool) -> &str {
"RangeInclusive<i64>"
};
}
if name == type_name::<BitRange>() {
return if shorthands { "range" } else { "BitRange" };
}
if name == type_name::<CharsStream>() {
return if shorthands { "range" } else { "CharStream" };
}

let step_range_name = type_name::<StepRange<u8>>();
let step_range_name = &step_range_name[..step_range_name.len() - 3];

if name.starts_with(step_range_name) && name.ends_with('>') {
return if shorthands {
"range"
} else {
let step_range_name = step_range_name.split("::").last().unwrap();
&step_range_name[..step_range_name.len() - 1]
};
}

#[cfg(not(feature = "no_float"))]
if name == type_name::<crate::packages::iter_basic::float::StepFloatRange>() {
return if shorthands {
"range"
} else {
"StepFloatRange"
};
}
#[cfg(feature = "decimal")]
if name == type_name::<crate::packages::iter_basic::decimal::StepDecimalRange>() {
return if shorthands {
"range"
} else {
"StepDecimalRange"
};
}

if name.starts_with("rhai::") {
map_std_type_name(&name[6..], shorthands)
Expand Down
8 changes: 2 additions & 6 deletions src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,7 @@ impl Expr {
/// `non_qualified` is ignored under `no_module`.
#[inline]
#[must_use]
pub(crate) fn is_variable_access(&self, non_qualified: bool) -> bool {
let _non_qualified = non_qualified;

pub(crate) fn is_variable_access(&self, _non_qualified: bool) -> bool {
match self {
#[cfg(not(feature = "no_module"))]
Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => false,
Expand All @@ -651,9 +649,7 @@ impl Expr {
/// `non_qualified` is ignored under `no_module`.
#[inline]
#[must_use]
pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> {
let _non_qualified = non_qualified;

pub(crate) fn get_variable_name(&self, _non_qualified: bool) -> Option<&str> {
match self {
#[cfg(not(feature = "no_module"))]
Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => None,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rhai-dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn debug_callback(
let mut input = String::new();

loop {
print!("rhai-dbg> ");
print!("dbg> ");

stdout().flush().expect("couldn't flush stdout");

Expand Down
23 changes: 9 additions & 14 deletions src/bin/rhai-repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST, INT};
use rustyline::config::Builder;
use rustyline::error::ReadlineError;
use rustyline::{Cmd, Editor, Event, EventHandler, KeyCode, KeyEvent, Modifiers, Movement};
use smallvec::smallvec;

use std::{env, fs::File, io::Read, path::Path, process::exit};

Expand Down Expand Up @@ -223,40 +222,40 @@ fn setup_editor() -> Editor<()> {
// On Windows, Esc clears the input buffer
#[cfg(target_family = "windows")]
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Esc, Modifiers::empty())]),
Event::KeySeq(vec![KeyEvent(KeyCode::Esc, Modifiers::empty())]),
EventHandler::Simple(Cmd::Kill(Movement::WholeBuffer)),
);
// On Windows, Ctrl-Z is undo
#[cfg(target_family = "windows")]
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent::ctrl('z')]),
Event::KeySeq(vec![KeyEvent::ctrl('z')]),
EventHandler::Simple(Cmd::Undo(1)),
);
// Map Ctrl-Enter to insert a new line - bypass need for `\` continuation
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Char('J'), Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::Char('J'), Modifiers::CTRL)]),
EventHandler::Simple(Cmd::Newline),
);
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Enter, Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::Enter, Modifiers::CTRL)]),
EventHandler::Simple(Cmd::Newline),
);
// Map Ctrl-Home and Ctrl-End for beginning/end of input
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Home, Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::Home, Modifiers::CTRL)]),
EventHandler::Simple(Cmd::Move(Movement::BeginningOfBuffer)),
);
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::End, Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::End, Modifiers::CTRL)]),
EventHandler::Simple(Cmd::Move(Movement::EndOfBuffer)),
);
// Map Ctrl-Up and Ctrl-Down to skip up/down the history, even through multi-line histories
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Down, Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::Down, Modifiers::CTRL)]),
EventHandler::Simple(Cmd::NextHistory),
);
rl.bind_sequence(
Event::KeySeq(smallvec![KeyEvent(KeyCode::Up, Modifiers::CTRL)]),
Event::KeySeq(vec![KeyEvent(KeyCode::Up, Modifiers::CTRL)]),
EventHandler::Simple(Cmd::PreviousHistory),
);

Expand Down Expand Up @@ -371,11 +370,7 @@ fn main() {
input.clear();

loop {
let prompt = if input.is_empty() {
"rhai-repl> "
} else {
" > "
};
let prompt = if input.is_empty() { "repl> " } else { " > " };

match rl.readline(prompt) {
// Line continuation
Expand Down
4 changes: 1 addition & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ impl Engine {
}

/// Check a result to ensure that it is valid.
pub(crate) fn check_return_value(&self, mut result: RhaiResult, pos: Position) -> RhaiResult {
let _pos = pos;

pub(crate) fn check_return_value(&self, mut result: RhaiResult, _pos: Position) -> RhaiResult {
match result {
Ok(ref mut r) => {
// Concentrate all empty strings into one instance to save memory
Expand Down
17 changes: 5 additions & 12 deletions src/eval/chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,14 @@ impl Engine {
this_ptr: &mut Option<&mut Dynamic>,
target: &mut Target,
root: (&str, Position),
parent: &Expr,
_parent: &Expr,
rhs: &Expr,
parent_options: ASTFlags,
_parent_options: ASTFlags,
idx_values: &mut StaticVec<super::ChainArgument>,
chain_type: ChainType,
level: usize,
new_val: Option<((Dynamic, Position), (Option<OpAssignment>, Position))>,
) -> RhaiResultOf<(Dynamic, bool)> {
let _parent = parent;
let _parent_options = parent_options;
let is_ref_mut = target.is_ref();

// Pop the last index value
Expand Down Expand Up @@ -671,16 +669,14 @@ impl Engine {
this_ptr: &mut Option<&mut Dynamic>,
expr: &Expr,
parent_options: ASTFlags,
parent_chain_type: ChainType,
_parent_chain_type: ChainType,
idx_values: &mut StaticVec<super::ChainArgument>,
size: usize,
level: usize,
) -> RhaiResultOf<()> {
#[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, expr.position())?;

let _parent_chain_type = parent_chain_type;

match expr {
#[cfg(not(feature = "no_object"))]
Expr::MethodCall(x, ..)
Expand Down Expand Up @@ -850,18 +846,15 @@ impl Engine {
state: &mut EvalState,
lib: &[&Module],
target: &'t mut Dynamic,
idx: Dynamic,
mut idx: Dynamic,
idx_pos: Position,
add_if_not_found: bool,
_add_if_not_found: bool,
use_indexers: bool,
level: usize,
) -> RhaiResultOf<Target<'t>> {
#[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, Position::NONE)?;

let mut idx = idx;
let _add_if_not_found = add_if_not_found;

match target {
#[cfg(not(feature = "no_index"))]
Dynamic(Union::Array(arr, ..)) => {
Expand Down
4 changes: 1 addition & 3 deletions src/eval/data_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ impl Engine {
///
/// Panics if any interior data is shared (should never happen).
#[cfg(not(feature = "unchecked"))]
pub(crate) fn calc_data_sizes(value: &Dynamic, top: bool) -> (usize, usize, usize) {
let _top = top;

pub(crate) fn calc_data_sizes(value: &Dynamic, _top: bool) -> (usize, usize, usize) {
match value.0 {
#[cfg(not(feature = "no_index"))]
Union::Array(ref arr, ..) => {
Expand Down

0 comments on commit 1616541

Please sign in to comment.