Refine packages.

This commit is contained in:
Stephen Chung
2020-08-20 22:11:41 +08:00
parent 38a6c15da1
commit 729ab99ec3
9 changed files with 210 additions and 191 deletions

View File

@@ -18,19 +18,24 @@ def_package!(crate:BasicMapPackage:"Basic object map utilities.", lib, {
#[export_module]
mod map_functions {
#[inline(always)]
pub fn has(map: &mut Map, prop: ImmutableString) -> bool {
map.contains_key(&prop)
}
#[inline(always)]
pub fn len(map: &mut Map) -> INT {
map.len() as INT
}
#[rhai_fn(get = "len")]
#[inline(always)]
pub fn len_prop(map: &mut Map) -> INT {
len(map)
}
#[inline(always)]
pub fn clear(map: &mut Map) {
map.clear();
}
#[inline]
pub fn remove(x: &mut Map, name: ImmutableString) -> Dynamic {
x.remove(&name).unwrap_or_else(|| ().into())
}
@@ -40,6 +45,7 @@ mod map_functions {
});
}
#[rhai_fn(name = "+=")]
#[inline(always)]
pub fn mixin_operator(map1: &mut Map, map2: Map) {
mixin(map1, map2)
}