Fix bug with calling a pure function method-call style.

This commit is contained in:
Stephen Chung
2020-05-11 18:55:58 +08:00
parent 4a8710a4a9
commit 414f3d3c23
8 changed files with 221 additions and 115 deletions

View File

@@ -118,9 +118,8 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
// Register array iterator
lib.type_iterators.insert(
TypeId::of::<Array>(),
Box::new(|a: Dynamic| {
Box::new(a.cast::<Array>().into_iter())
as Box<dyn Iterator<Item = Dynamic>>
}),
Box::new(|arr| Box::new(
arr.cast::<Array>().into_iter()) as Box<dyn Iterator<Item = Dynamic>>
),
);
});

View File

@@ -18,7 +18,7 @@ where
{
lib.type_iterators.insert(
TypeId::of::<Range<T>>(),
Box::new(|source: Dynamic| {
Box::new(|source| {
Box::new(source.cast::<Range<T>>().map(|x| x.into_dynamic()))
as Box<dyn Iterator<Item = Dynamic>>
}),
@@ -58,7 +58,7 @@ where
{
lib.type_iterators.insert(
TypeId::of::<StepRange<T>>(),
Box::new(|source: Dynamic| {
Box::new(|source| {
Box::new(source.cast::<StepRange<T>>().map(|x| x.into_dynamic()))
as Box<dyn Iterator<Item = Dynamic>>
}),

View File

@@ -2,7 +2,7 @@ use super::PackageStore;
use crate::any::{Dynamic, Variant};
use crate::calc_fn_hash;
use crate::fn_native::{FnCallArgs, NativeFunction};
use crate::fn_native::{FnCallArgs, NativeFunction, NativeFunctionABI::*};
use crate::result::EvalAltResult;
use crate::token::Position;
@@ -106,7 +106,8 @@ pub fn reg_none<R>(
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Pure)));
}
/// Add a function with one parameter to the package.
@@ -157,7 +158,8 @@ pub fn reg_unary<T: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Pure)));
}
/// Add a function with one mutable reference parameter to the package.
@@ -215,7 +217,8 @@ pub fn reg_unary_mut<T: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Method)));
}
/// Add a function with two parameters to the package.
@@ -271,7 +274,8 @@ pub fn reg_binary<A: Variant + Clone, B: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Pure)));
}
/// Add a function with two parameters (the first one being a mutable reference) to the package.
@@ -334,7 +338,8 @@ pub fn reg_binary_mut<A: Variant + Clone, B: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Method)));
}
/// Add a function with three parameters to the package.
@@ -374,7 +379,8 @@ pub fn reg_trinary<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, R
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Pure)));
}
/// Add a function with three parameters (the first one is a mutable reference) to the package.
@@ -414,5 +420,6 @@ pub fn reg_trinary_mut<A: Variant + Clone, B: Variant + Clone, C: Variant + Clon
map_result(r, pos)
});
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
lib.functions
.insert(hash, Box::new(NativeFunction::new(f, Method)));
}