diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b635c8..291d56c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ Rhai Release Notes Version 1.2.0 ============= -Breaking changes for scripts ---------------------------- +Bug fixes with breaking script changes +------------------------------------- * As originally intended, function calls with a bang (`!`) now operates directly on the caller's scope, allowing variables inside the scope to be mutated. * As originally intended, `Engine::XXX_with_scope` API's now properly propagate constants within the provided scope also to _functions_ in the script. diff --git a/src/api/public.rs b/src/api/public.rs index 101bcb37..08a695b4 100644 --- a/src/api/public.rs +++ b/src/api/public.rs @@ -1,7 +1,7 @@ //! Module that defines the public API of [`Engine`]. use crate::engine::{EvalContext, EvalState, Imports}; -use crate::func::{call::FnCallArgs, native::SendSync, register::RegisterNativeFunction}; +use crate::func::{FnCallArgs, RegisterNativeFunction, SendSync}; use crate::parser::ParseState; use crate::types::dynamic::Variant; use crate::{ diff --git a/src/engine.rs b/src/engine.rs index 294b9bab..91a53af5 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -3,11 +3,9 @@ use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; use crate::custom_syntax::CustomSyntax; use crate::func::{ - hashing::get_hasher, - native::{ - CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback, - OnVarCallback, - }, + get_hasher, + native::{OnDebugCallback, OnParseTokenCallback, OnPrintCallback, OnVarCallback}, + CallableFunction, IteratorFn, }; use crate::module::NamespaceRef; use crate::packages::{Package, StandardPackage}; diff --git a/src/func/call.rs b/src/func/call.rs index 84214d92..0d08f378 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1,7 +1,7 @@ //! Implement function-calling mechanism for [`Engine`]. -use super::builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn}; use super::native::{CallableFunction, FnAny}; +use super::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn}; use crate::ast::FnCallHashes; use crate::engine::{ EvalState, FnResolutionCacheEntry, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, diff --git a/src/func/hashing.rs b/src/func/hashing.rs index fcb66e76..952e5a72 100644 --- a/src/func/hashing.rs +++ b/src/func/hashing.rs @@ -14,7 +14,7 @@ use std::{ /// /// Panics when hashing any data type other than a [`u64`]. #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct StraightHasher(u64); +struct StraightHasher(u64); impl Hasher for StraightHasher { #[inline(always)] @@ -34,7 +34,7 @@ impl Hasher for StraightHasher { /// A hash builder for `StraightHasher`. #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Default)] -pub struct StraightHasherBuilder; +struct StraightHasherBuilder; impl BuildHasher for StraightHasherBuilder { type Hasher = StraightHasher; @@ -135,6 +135,6 @@ pub fn calc_fn_params_hash(params: impl Iterator) -> u64 { /// Combine two [`u64`] hashes by taking the XOR of them. #[inline(always)] #[must_use] -pub(crate) const fn combine_hashes(a: u64, b: u64) -> u64 { +pub const fn combine_hashes(a: u64, b: u64) -> u64 { a ^ b } diff --git a/src/func/mod.rs b/src/func/mod.rs index 59e83937..ffeb578a 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -8,3 +8,18 @@ pub mod hashing; pub mod native; pub mod plugin; pub mod register; + +pub use args::FuncArgs; +pub use builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn}; +pub use call::FnCallArgs; +pub use func::Func; +pub use hashing::{ + calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash, + combine_hashes, get_hasher, +}; +pub use native::{ + shared_make_mut, shared_take, shared_take_or_clone, shared_try_take, shared_write_lock, + CallableFunction, FnAny, FnPlugin, IteratorFn, Locked, NativeCallContext, SendSync, Shared, +}; +pub use plugin::PluginFunction; +pub use register::RegisterNativeFunction; diff --git a/src/func/plugin.rs b/src/func/plugin.rs index b508c52d..3faf408b 100644 --- a/src/func/plugin.rs +++ b/src/func/plugin.rs @@ -1,7 +1,7 @@ //! Module defining macros for developing _plugins_. -use super::call::FnCallArgs; -pub use super::native::CallableFunction; +pub use super::CallableFunction; +use super::FnCallArgs; pub use crate::{ Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module, NativeCallContext, Position, @@ -9,6 +9,7 @@ pub use crate::{ #[cfg(feature = "no_std")] use std::prelude::v1::*; pub use std::{any::TypeId, mem}; + pub type RhaiResult = Result>; #[cfg(not(features = "no_module"))] diff --git a/src/lib.rs b/src/lib.rs index 861bee3f..5d7a7776 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,16 +119,11 @@ pub type FLOAT = f32; pub use ast::{FnAccess, AST}; pub use custom_syntax::Expression; pub use engine::{Engine, EvalContext, OP_CONTAINS, OP_EQUALS}; -pub use func::{native::NativeCallContext, register::RegisterNativeFunction}; +pub use func::{NativeCallContext, RegisterNativeFunction}; pub use module::{FnNamespace, Module}; pub use tokenizer::Position; pub use types::{ - dynamic::Dynamic, - error::EvalAltResult, - fn_ptr::FnPtr, - immutable_string::ImmutableString, - parse_error::{LexError, ParseError, ParseErrorType}, - scope::Scope, + Dynamic, EvalAltResult, FnPtr, ImmutableString, LexError, ParseError, ParseErrorType, Scope, }; /// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most @@ -156,12 +151,12 @@ pub type Identifier = SmartString; pub type Identifier = ImmutableString; /// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag. -pub use func::native::Shared; +pub use func::Shared; /// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag. -pub use func::native::Locked; +pub use func::Locked; -pub(crate) use func::hashing::{ +pub(crate) use func::{ calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash, combine_hashes, }; @@ -171,7 +166,7 @@ pub use rhai_codegen::*; pub use func::plugin; #[cfg(not(feature = "no_function"))] -pub use func::{args::FuncArgs, func::Func}; +pub use func::{Func, FuncArgs}; #[cfg(not(feature = "no_function"))] pub use ast::ScriptFnMetadata; diff --git a/src/module/mod.rs b/src/module/mod.rs index 6d5f3975..fb2835e5 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -2,9 +2,8 @@ use crate::ast::{FnAccess, Ident}; use crate::func::{ - call::FnCallArgs, - native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync}, - register::RegisterNativeFunction, + shared_take_or_clone, CallableFunction, FnCallArgs, IteratorFn, RegisterNativeFunction, + SendSync, }; use crate::parser::IdentifierBuilder; use crate::tokenizer::Token; diff --git a/src/types/mod.rs b/src/types/mod.rs index ee2ff553..d20c2242 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -6,3 +6,10 @@ pub mod fn_ptr; pub mod immutable_string; pub mod parse_error; pub mod scope; + +pub use dynamic::Dynamic; +pub use error::EvalAltResult; +pub use fn_ptr::FnPtr; +pub use immutable_string::ImmutableString; +pub use parse_error::{LexError, ParseError, ParseErrorType}; +pub use scope::Scope;