Merge pull request #65 from tguichaoua/type_builder_iterable
with_iterator --> is_iterable
This commit is contained in:
commit
ceaf9fab1b
@ -49,7 +49,7 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
.with_fn("new_ts", Self::new)
|
||||
.with_fn("update", Self::update)
|
||||
.with_fn("calc", Self::calculate)
|
||||
.with_iterator()
|
||||
.is_iterable()
|
||||
.with_get_set("x", Self::get_x, Self::set_x);
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ where
|
||||
/// Register a type iterator.
|
||||
/// This is an advanced API.
|
||||
#[inline(always)]
|
||||
pub fn with_iterator(&mut self) -> &mut Self {
|
||||
pub fn is_iterable(&mut self) -> &mut Self {
|
||||
self.engine.register_iterator::<T>();
|
||||
self
|
||||
}
|
||||
|
@ -58,8 +58,9 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
|
||||
fn build(mut builder: TypeBuilder<Self>) {
|
||||
builder
|
||||
.with_name("Vec3")
|
||||
.is_iterable()
|
||||
.with_fn("vec3", Self::new)
|
||||
.with_iterator()
|
||||
.is_iterable()
|
||||
.with_get_set("x", Self::get_x, Self::set_x)
|
||||
.with_get_set("y", Self::get_y, Self::set_y)
|
||||
.with_get_set("z", Self::get_z, Self::set_z);
|
||||
@ -127,6 +128,19 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
|
||||
)?,
|
||||
Vec3::new(5, 6, 7),
|
||||
);
|
||||
assert_eq!(
|
||||
engine.eval::<INT>(
|
||||
"
|
||||
let sum = 0;
|
||||
let v = vec3(1, 2, 3);
|
||||
for i in v {
|
||||
sum += i;
|
||||
}
|
||||
sum
|
||||
",
|
||||
)?,
|
||||
6,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user