diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index b641db3e..8b56be54 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -23,23 +23,25 @@ pub type Unit = (); macro_rules! gen_array_functions { ($root:ident => $($arg_type:ident),+ ) => { - pub mod $root { $(pub mod $arg_type { + pub mod $root { $( pub mod $arg_type { use super::super::*; - #[export_fn] - #[inline(always)] - pub fn push(list: &mut Array, item: $arg_type) { - list.push(Dynamic::from(item)); - } + #[export_module] + pub mod functions { + #[rhai_fn(name = "push", name = "+=")] + #[inline(always)] + pub fn push(list: &mut Array, item: $arg_type) { + list.push(Dynamic::from(item)); + } - #[export_fn] - pub fn insert(list: &mut Array, position: INT, item: $arg_type) { - if position <= 0 { - list.insert(0, Dynamic::from(item)); - } else if (position as usize) >= list.len() - 1 { - push(list, item); - } else { - list.insert(position as usize, Dynamic::from(item)); + pub fn insert(list: &mut Array, position: INT, item: $arg_type) { + if position <= 0 { + list.insert(0, Dynamic::from(item)); + } else if (position as usize) >= list.len() - 1 { + push(list, item); + } else { + list.insert(position as usize, Dynamic::from(item)); + } } } })* } @@ -48,9 +50,7 @@ macro_rules! gen_array_functions { macro_rules! reg_functions { ($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $( - set_exported_fn!($mod_name, "push", $root::$arg_type::push); - set_exported_fn!($mod_name, "+=", $root::$arg_type::push); - set_exported_fn!($mod_name, "insert", $root::$arg_type::insert); + combine_with_exported_module!($mod_name, "array_functions", $root::$arg_type::functions); $mod_name.set_raw_fn("pad", &[TypeId::of::(), TypeId::of::(), TypeId::of::<$arg_type>()], diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 55fa4be0..413e78a2 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -17,28 +17,30 @@ use crate::stdlib::{ macro_rules! gen_concat_functions { ($root:ident => $($arg_type:ident),+ ) => { - pub mod $root { $(pub mod $arg_type { + pub mod $root { $( pub mod $arg_type { use super::super::*; - #[export_fn] - #[inline] - pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String { - format!("{}{}", x, y) - } + #[export_module] + pub mod functions { + #[rhai_fn(name = "+")] + #[inline] + pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String { + format!("{}{}", x, y) + } - #[export_fn] - #[inline] - pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String { - format!("{}{}", x, y) + #[rhai_fn(name = "+")] + #[inline] + pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String { + format!("{}{}", x, y) + } } - })* } + } )* } } } macro_rules! reg_functions { ($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $( - set_exported_fn!($mod_name, "+", $root::$arg_type::append_func); - set_exported_fn!($mod_name, "+", $root::$arg_type::prepend_func); + combine_with_exported_module!($mod_name, "append", $root::$arg_type::functions); )* } }