commit
15292f4aa8
@ -7,10 +7,10 @@ Version 0.17.0
|
||||
This version adds:
|
||||
|
||||
* [`serde`](https://crates.io/crates/serde) support for working with `Dynamic` values (particularly _object maps_).
|
||||
* Low-level API to register functions.
|
||||
* Surgically disable keywords and/or operators in the language.
|
||||
* Define custom operators.
|
||||
* Extend the language via custom syntax.
|
||||
* Low-level API to register functions.
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
@ -41,6 +41,7 @@ New features
|
||||
* Many configuration/setting API's now returns `&mut Self` so that the calls can be chained.
|
||||
* `String` parameters in functions are supported (but inefficiently).
|
||||
|
||||
|
||||
Version 0.16.1
|
||||
==============
|
||||
|
||||
|
@ -212,9 +212,11 @@ pub(crate) fn map_std_type_name(name: &str) -> &str {
|
||||
"string"
|
||||
} else if name == type_name::<FnPtr>() {
|
||||
"Fn"
|
||||
} else if name == type_name::<Instant>() {
|
||||
"timestamp"
|
||||
} else {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
if name == type_name::<Instant>() {
|
||||
return "timestamp";
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
if name == type_name::<Array>() {
|
||||
return "array";
|
||||
|
@ -26,7 +26,7 @@ use crate::stdlib::{
|
||||
boxed::Box,
|
||||
collections::{HashMap, HashSet},
|
||||
convert::TryFrom,
|
||||
format,
|
||||
fmt, format,
|
||||
iter::{empty, once},
|
||||
mem,
|
||||
string::{String, ToString},
|
||||
@ -96,6 +96,7 @@ pub const MARKER_BLOCK: &str = "$block$";
|
||||
pub const MARKER_IDENT: &str = "$ident$";
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Expression<'a>(&'a Expr);
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
@ -346,6 +347,15 @@ pub struct Engine {
|
||||
pub(crate) max_map_size: usize,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Engine {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.id.as_ref() {
|
||||
Some(id) => write!(f, "Engine({})", id),
|
||||
None => f.write_str("Engine"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Engine {
|
||||
fn default() -> Self {
|
||||
// Create the new scripting Engine
|
||||
@ -1095,6 +1105,7 @@ impl Engine {
|
||||
let mut hash = *hash;
|
||||
|
||||
// Check if it is a map method call in OOP style
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
if let Some(map) = obj.downcast_ref::<Map>() {
|
||||
if let Some(val) = map.get(fn_name) {
|
||||
if let Some(f) = val.downcast_ref::<FnPtr>() {
|
||||
|
@ -7,7 +7,7 @@ use crate::result::EvalAltResult;
|
||||
use crate::token::{is_valid_identifier, Position};
|
||||
use crate::utils::ImmutableString;
|
||||
|
||||
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, rc::Rc, sync::Arc};
|
||||
use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, rc::Rc, string::String, sync::Arc};
|
||||
|
||||
/// Trait that maps to `Send + Sync` only under the `sync` feature.
|
||||
#[cfg(feature = "sync")]
|
||||
@ -86,7 +86,7 @@ impl TryFrom<ImmutableString> for FnPtr {
|
||||
Ok(Self(value))
|
||||
} else {
|
||||
Err(Box::new(EvalAltResult::ErrorFunctionNotFound(
|
||||
value.to_string(),
|
||||
value.into(),
|
||||
Position::none(),
|
||||
)))
|
||||
}
|
||||
|
@ -10,7 +10,12 @@ use crate::r#unsafe::unsafe_cast_box;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::utils::ImmutableString;
|
||||
|
||||
use crate::stdlib::{any::TypeId, boxed::Box, mem};
|
||||
use crate::stdlib::{
|
||||
any::TypeId,
|
||||
boxed::Box,
|
||||
mem,
|
||||
string::{String, ToString},
|
||||
};
|
||||
|
||||
/// Trait to register custom functions with the `Engine`.
|
||||
pub trait RegisterFn<FN, ARGS, RET> {
|
||||
|
@ -25,11 +25,13 @@ use crate::stdlib::{
|
||||
num::NonZeroUsize,
|
||||
ops::{Deref, DerefMut},
|
||||
string::{String, ToString},
|
||||
sync::RwLock,
|
||||
vec,
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use crate::stdlib::sync::RwLock;
|
||||
|
||||
/// Return type of module-level Rust function.
|
||||
pub type FuncReturn<T> = Result<T, Box<EvalAltResult>>;
|
||||
|
||||
|
@ -52,7 +52,7 @@ pub type PackageLibrary = Shared<Module>;
|
||||
|
||||
/// Type containing a collection of `PackageLibrary` instances.
|
||||
/// All function and type iterator keys in the loaded packages are indexed for fast access.
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub(crate) struct PackagesCollection(StaticVec<PackageLibrary>);
|
||||
|
||||
impl PackagesCollection {
|
||||
|
@ -4,6 +4,8 @@ use crate::optimize::OptimizationLevel;
|
||||
use crate::packages::PackageLibrary;
|
||||
use crate::token::is_valid_identifier;
|
||||
|
||||
use crate::stdlib::{boxed::Box, format, string::String};
|
||||
|
||||
impl Engine {
|
||||
/// Load a new package into the `Engine`.
|
||||
///
|
||||
|
@ -16,7 +16,7 @@ mod inner {
|
||||
pub use core_error as error;
|
||||
|
||||
pub mod collections {
|
||||
pub use hashbrown::HashMap;
|
||||
pub use hashbrown::{HashMap, HashSet};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ impl Engine {
|
||||
) -> Result<Dynamic, Box<EvalAltResult>>
|
||||
+ SendSync
|
||||
+ 'static,
|
||||
) -> Result<self, Box<LexError>> {
|
||||
) -> Result<&mut Self, Box<LexError>> {
|
||||
if value.is_empty() {
|
||||
return Err(Box::new(LexError::ImproperSymbol("".to_string())));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use crate::stdlib::{
|
||||
boxed::Box,
|
||||
char,
|
||||
collections::HashMap,
|
||||
fmt,
|
||||
fmt, format,
|
||||
iter::Peekable,
|
||||
str::{Chars, FromStr},
|
||||
string::{String, ToString},
|
||||
|
@ -115,6 +115,7 @@ fn test_anonymous_fn() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
|
@ -35,6 +35,7 @@ fn test_tokens_custom_operator() -> Result<(), Box<EvalAltResult>> {
|
||||
15
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
r"
|
||||
|
Loading…
Reference in New Issue
Block a user