Level up exports.

This commit is contained in:
Stephen Chung 2021-11-16 12:26:37 +08:00
parent 98707912e0
commit 2fffe31b59
10 changed files with 43 additions and 28 deletions

View File

@ -4,8 +4,8 @@ Rhai Release Notes
Version 1.2.0 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, 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. * As originally intended, `Engine::XXX_with_scope` API's now properly propagate constants within the provided scope also to _functions_ in the script.

View File

@ -1,7 +1,7 @@
//! Module that defines the public API of [`Engine`]. //! Module that defines the public API of [`Engine`].
use crate::engine::{EvalContext, EvalState, Imports}; 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::parser::ParseState;
use crate::types::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::{ use crate::{

View File

@ -3,11 +3,9 @@
use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*};
use crate::custom_syntax::CustomSyntax; use crate::custom_syntax::CustomSyntax;
use crate::func::{ use crate::func::{
hashing::get_hasher, get_hasher,
native::{ native::{OnDebugCallback, OnParseTokenCallback, OnPrintCallback, OnVarCallback},
CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback, CallableFunction, IteratorFn,
OnVarCallback,
},
}; };
use crate::module::NamespaceRef; use crate::module::NamespaceRef;
use crate::packages::{Package, StandardPackage}; use crate::packages::{Package, StandardPackage};

View File

@ -1,7 +1,7 @@
//! Implement function-calling mechanism for [`Engine`]. //! 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::native::{CallableFunction, FnAny};
use super::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn};
use crate::ast::FnCallHashes; use crate::ast::FnCallHashes;
use crate::engine::{ use crate::engine::{
EvalState, FnResolutionCacheEntry, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, EvalState, FnResolutionCacheEntry, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR,

View File

@ -14,7 +14,7 @@ use std::{
/// ///
/// Panics when hashing any data type other than a [`u64`]. /// Panics when hashing any data type other than a [`u64`].
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct StraightHasher(u64); struct StraightHasher(u64);
impl Hasher for StraightHasher { impl Hasher for StraightHasher {
#[inline(always)] #[inline(always)]
@ -34,7 +34,7 @@ impl Hasher for StraightHasher {
/// A hash builder for `StraightHasher`. /// A hash builder for `StraightHasher`.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Default)] #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
pub struct StraightHasherBuilder; struct StraightHasherBuilder;
impl BuildHasher for StraightHasherBuilder { impl BuildHasher for StraightHasherBuilder {
type Hasher = StraightHasher; type Hasher = StraightHasher;
@ -135,6 +135,6 @@ pub fn calc_fn_params_hash(params: impl Iterator<Item = TypeId>) -> u64 {
/// Combine two [`u64`] hashes by taking the XOR of them. /// Combine two [`u64`] hashes by taking the XOR of them.
#[inline(always)] #[inline(always)]
#[must_use] #[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 a ^ b
} }

View File

@ -8,3 +8,18 @@ pub mod hashing;
pub mod native; pub mod native;
pub mod plugin; pub mod plugin;
pub mod register; 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;

View File

@ -1,7 +1,7 @@
//! Module defining macros for developing _plugins_. //! Module defining macros for developing _plugins_.
use super::call::FnCallArgs; pub use super::CallableFunction;
pub use super::native::CallableFunction; use super::FnCallArgs;
pub use crate::{ pub use crate::{
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
NativeCallContext, Position, NativeCallContext, Position,
@ -9,6 +9,7 @@ pub use crate::{
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
pub use std::{any::TypeId, mem}; pub use std::{any::TypeId, mem};
pub type RhaiResult = Result<Dynamic, Box<EvalAltResult>>; pub type RhaiResult = Result<Dynamic, Box<EvalAltResult>>;
#[cfg(not(features = "no_module"))] #[cfg(not(features = "no_module"))]

View File

@ -119,16 +119,11 @@ pub type FLOAT = f32;
pub use ast::{FnAccess, AST}; pub use ast::{FnAccess, AST};
pub use custom_syntax::Expression; pub use custom_syntax::Expression;
pub use engine::{Engine, EvalContext, OP_CONTAINS, OP_EQUALS}; 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 module::{FnNamespace, Module};
pub use tokenizer::Position; pub use tokenizer::Position;
pub use types::{ pub use types::{
dynamic::Dynamic, Dynamic, EvalAltResult, FnPtr, ImmutableString, LexError, ParseError, ParseErrorType, Scope,
error::EvalAltResult,
fn_ptr::FnPtr,
immutable_string::ImmutableString,
parse_error::{LexError, ParseError, ParseErrorType},
scope::Scope,
}; };
/// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most /// 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; pub type Identifier = ImmutableString;
/// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag. /// 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. /// 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, calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
combine_hashes, combine_hashes,
}; };
@ -171,7 +166,7 @@ pub use rhai_codegen::*;
pub use func::plugin; pub use func::plugin;
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use func::{args::FuncArgs, func::Func}; pub use func::{Func, FuncArgs};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
pub use ast::ScriptFnMetadata; pub use ast::ScriptFnMetadata;

View File

@ -2,9 +2,8 @@
use crate::ast::{FnAccess, Ident}; use crate::ast::{FnAccess, Ident};
use crate::func::{ use crate::func::{
call::FnCallArgs, shared_take_or_clone, CallableFunction, FnCallArgs, IteratorFn, RegisterNativeFunction,
native::{shared_take_or_clone, CallableFunction, IteratorFn, SendSync}, SendSync,
register::RegisterNativeFunction,
}; };
use crate::parser::IdentifierBuilder; use crate::parser::IdentifierBuilder;
use crate::tokenizer::Token; use crate::tokenizer::Token;

View File

@ -6,3 +6,10 @@ pub mod fn_ptr;
pub mod immutable_string; pub mod immutable_string;
pub mod parse_error; pub mod parse_error;
pub mod scope; 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;