Minor code cleanup.

This commit is contained in:
Stephen Chung 2020-03-14 23:41:21 +08:00
parent 01cf777961
commit f80e499e84
2 changed files with 11 additions and 11 deletions

View File

@ -580,7 +580,7 @@ impl Engine<'_> {
} }
fn range<T>(from: T, to: T) -> Range<T> { fn range<T>(from: T, to: T) -> Range<T> {
(from..to) from..to
} }
reg_iterator::<INT>(self); reg_iterator::<INT>(self);
@ -773,9 +773,12 @@ impl Engine<'_> {
self.register_dynamic_fn("pop", |list: &mut Array| { self.register_dynamic_fn("pop", |list: &mut Array| {
list.pop().unwrap_or_else(|| ().into_dynamic()) list.pop().unwrap_or_else(|| ().into_dynamic())
}); });
self.register_dynamic_fn("shift", |list: &mut Array| match list.len() { self.register_dynamic_fn("shift", |list: &mut Array| {
0 => ().into_dynamic(), if !list.is_empty() {
_ => list.remove(0), ().into_dynamic()
} else {
list.remove(0)
}
}); });
self.register_fn("len", |list: &mut Array| list.len() as INT); self.register_fn("len", |list: &mut Array| list.len() as INT);
self.register_fn("clear", |list: &mut Array| list.clear()); self.register_fn("clear", |list: &mut Array| list.clear());

View File

@ -196,13 +196,10 @@ macro_rules! def_register {
// Call the user-supplied function using ($clone) to // Call the user-supplied function using ($clone) to
// potentially clone the value, otherwise pass the reference. // potentially clone the value, otherwise pass the reference.
match f($(($clone)($par)),*) { f($(($clone)($par)),*).map(|r| Box::new(r) as Dynamic).map_err(|mut err| {
Ok(r) => Ok(Box::new(r) as Dynamic), err.set_position(pos);
Err(mut err) => { err
err.set_position(pos); })
Err(err)
}
}
}; };
self.register_fn_raw(name, Some(vec![$(TypeId::of::<$par>()),*]), Box::new(fun)); self.register_fn_raw(name, Some(vec![$(TypeId::of::<$par>()),*]), Box::new(fun));
} }