Use modules.
This commit is contained in:
parent
e7566da7d2
commit
41a16c9cf7
@ -23,16 +23,17 @@ pub type Unit = ();
|
|||||||
|
|
||||||
macro_rules! gen_array_functions {
|
macro_rules! gen_array_functions {
|
||||||
($root:ident => $($arg_type:ident),+ ) => {
|
($root:ident => $($arg_type:ident),+ ) => {
|
||||||
pub mod $root { $(pub mod $arg_type {
|
pub mod $root { $( pub mod $arg_type {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_module]
|
||||||
|
pub mod functions {
|
||||||
|
#[rhai_fn(name = "push", name = "+=")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn push(list: &mut Array, item: $arg_type) {
|
pub fn push(list: &mut Array, item: $arg_type) {
|
||||||
list.push(Dynamic::from(item));
|
list.push(Dynamic::from(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_fn]
|
|
||||||
pub fn insert(list: &mut Array, position: INT, item: $arg_type) {
|
pub fn insert(list: &mut Array, position: INT, item: $arg_type) {
|
||||||
if position <= 0 {
|
if position <= 0 {
|
||||||
list.insert(0, Dynamic::from(item));
|
list.insert(0, Dynamic::from(item));
|
||||||
@ -42,15 +43,14 @@ macro_rules! gen_array_functions {
|
|||||||
list.insert(position as usize, Dynamic::from(item));
|
list.insert(position as usize, Dynamic::from(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})* }
|
})* }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! reg_functions {
|
macro_rules! reg_functions {
|
||||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||||
set_exported_fn!($mod_name, "push", $root::$arg_type::push);
|
combine_with_exported_module!($mod_name, "array_functions", $root::$arg_type::functions);
|
||||||
set_exported_fn!($mod_name, "+=", $root::$arg_type::push);
|
|
||||||
set_exported_fn!($mod_name, "insert", $root::$arg_type::insert);
|
|
||||||
|
|
||||||
$mod_name.set_raw_fn("pad",
|
$mod_name.set_raw_fn("pad",
|
||||||
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$arg_type>()],
|
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$arg_type>()],
|
||||||
|
@ -17,28 +17,30 @@ use crate::stdlib::{
|
|||||||
|
|
||||||
macro_rules! gen_concat_functions {
|
macro_rules! gen_concat_functions {
|
||||||
($root:ident => $($arg_type:ident),+ ) => {
|
($root:ident => $($arg_type:ident),+ ) => {
|
||||||
pub mod $root { $(pub mod $arg_type {
|
pub mod $root { $( pub mod $arg_type {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
#[export_fn]
|
#[export_module]
|
||||||
|
pub mod functions {
|
||||||
|
#[rhai_fn(name = "+")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String {
|
pub fn append_func(x: &mut ImmutableString, y: $arg_type) -> String {
|
||||||
format!("{}{}", x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_fn]
|
#[rhai_fn(name = "+")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String {
|
pub fn prepend_func(x: &mut $arg_type, y: ImmutableString) -> String {
|
||||||
format!("{}{}", x, y)
|
format!("{}{}", x, y)
|
||||||
}
|
}
|
||||||
})* }
|
}
|
||||||
|
} )* }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! reg_functions {
|
macro_rules! reg_functions {
|
||||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||||
set_exported_fn!($mod_name, "+", $root::$arg_type::append_func);
|
combine_with_exported_module!($mod_name, "append", $root::$arg_type::functions);
|
||||||
set_exported_fn!($mod_name, "+", $root::$arg_type::prepend_func);
|
|
||||||
)* }
|
)* }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user