Merge pull request #44 from schungx/plugins_dev
Add missing pub's and refactor packages.
This commit is contained in:
commit
a50da4bb8c
@ -197,17 +197,17 @@ macro_rules! gen_arithmetic_functions {
|
||||
}
|
||||
#[rhai_fn(name = "&")]
|
||||
#[inline(always)]
|
||||
fn binary_and(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
pub fn binary_and(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x & y
|
||||
}
|
||||
#[rhai_fn(name = "|")]
|
||||
#[inline(always)]
|
||||
fn binary_or(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
pub fn binary_or(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x | y
|
||||
}
|
||||
#[rhai_fn(name = "^")]
|
||||
#[inline(always)]
|
||||
fn binary_xor(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
pub fn binary_xor(x: $arg_type, y: $arg_type) -> $arg_type {
|
||||
x ^ y
|
||||
}
|
||||
}
|
||||
@ -265,9 +265,9 @@ macro_rules! gen_signed_functions {
|
||||
}
|
||||
|
||||
macro_rules! reg_functions {
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+ ) => {
|
||||
$($mod_name.combine_flatten(exported_module!($root::$arg_type::functions));)*
|
||||
}
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+ ) => { $(
|
||||
$mod_name.combine_flatten(exported_module!($root::$arg_type::functions));
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
|
||||
@ -288,7 +288,10 @@ def_package!(crate:ArithmeticPackage:"Basic arithmetic", lib, {
|
||||
|
||||
// Basic arithmetic for floating-point
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
lib.combine_flatten(exported_module!(float_functions));
|
||||
{
|
||||
lib.combine_flatten(exported_module!(f32_functions));
|
||||
lib.combine_flatten(exported_module!(f64_functions));
|
||||
}
|
||||
});
|
||||
|
||||
gen_arithmetic_functions!(arith_basic => INT);
|
||||
@ -315,7 +318,7 @@ gen_signed_functions!(signed_num_128 => i128);
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod float_functions {
|
||||
mod f32_functions {
|
||||
#[rhai_fn(name = "+")]
|
||||
#[inline(always)]
|
||||
pub fn add(x: f32, y: f32) -> f32 {
|
||||
@ -343,38 +346,15 @@ mod float_functions {
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn neg_f32(x: f32) -> f32 {
|
||||
pub fn neg(x: f32) -> f32 {
|
||||
-x
|
||||
}
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn neg_f64(x: f64) -> f64 {
|
||||
-x
|
||||
}
|
||||
#[rhai_fn(name = "abs")]
|
||||
#[inline(always)]
|
||||
pub fn abs_f32(x: f32) -> f32 {
|
||||
pub fn abs(x: f32) -> f32 {
|
||||
x.abs()
|
||||
}
|
||||
#[rhai_fn(name = "abs")]
|
||||
#[inline(always)]
|
||||
pub fn abs_f64(x: f64) -> f64 {
|
||||
x.abs()
|
||||
}
|
||||
#[rhai_fn(name = "sign")]
|
||||
#[inline]
|
||||
pub fn sign_f32(x: f32) -> INT {
|
||||
if x == 0.0 {
|
||||
0
|
||||
} else if x < 0.0 {
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "sign")]
|
||||
#[inline]
|
||||
pub fn sign_f64(x: f64) -> INT {
|
||||
pub fn sign(x: f32) -> INT {
|
||||
if x == 0.0 {
|
||||
0
|
||||
} else if x < 0.0 {
|
||||
@ -385,8 +365,45 @@ mod float_functions {
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline(always)]
|
||||
pub fn pow_f_f(x: FLOAT, y: FLOAT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(x.powf(y).into())
|
||||
pub fn pow_f_f(x: f32, y: f32) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
Ok(Dynamic::from(x.powf(y)))
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline]
|
||||
pub fn pow_f_i(x: f32, y: INT) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
if cfg!(not(feature = "unchecked")) && y > (i32::MAX as INT) {
|
||||
EvalAltResult::ErrorArithmetic(
|
||||
format!("Number raised to too large an index: {} ~ {}", x, y),
|
||||
Position::none(),
|
||||
)
|
||||
.into()
|
||||
} else {
|
||||
Ok(Dynamic::from(x.powi(y as i32)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[export_module]
|
||||
mod f64_functions {
|
||||
#[rhai_fn(name = "-")]
|
||||
#[inline(always)]
|
||||
pub fn neg(x: f64) -> f64 {
|
||||
-x
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn abs(x: f64) -> f64 {
|
||||
x.abs()
|
||||
}
|
||||
#[inline]
|
||||
pub fn sign(x: f64) -> INT {
|
||||
if x == 0.0 {
|
||||
0
|
||||
} else if x < 0.0 {
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
#[rhai_fn(name = "~", return_raw)]
|
||||
#[inline]
|
||||
|
@ -11,6 +11,9 @@ use crate::plugin::*;
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
use crate::{result::EvalAltResult, token::Position};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use crate::engine::Map;
|
||||
|
||||
use crate::stdlib::{any::TypeId, boxed::Box};
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
@ -41,47 +44,35 @@ 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_func);)*
|
||||
$(set_exported_fn!($mod_name, "insert", $root::$arg_type::insert_func);)*
|
||||
}
|
||||
}
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||
set_exported_fn!($mod_name, "push", $root::$arg_type::push_func);
|
||||
set_exported_fn!($mod_name, "insert", $root::$arg_type::insert_func);
|
||||
|
||||
macro_rules! reg_pad {
|
||||
($lib:expr, $($par:ty),*) => {
|
||||
$({
|
||||
$lib.set_raw_fn("pad",
|
||||
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$par>()],
|
||||
pad::<$par>
|
||||
);
|
||||
})*
|
||||
};
|
||||
$mod_name.set_raw_fn("pad",
|
||||
&[TypeId::of::<Array>(), TypeId::of::<INT>(), TypeId::of::<$arg_type>()],
|
||||
pad::<$arg_type>);
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
|
||||
lib.combine_flatten(exported_module!(array_functions));
|
||||
|
||||
reg_functions!(lib += basic; INT, bool, char, ImmutableString, FnPtr, Array, Unit);
|
||||
reg_pad!(lib, INT, bool, char, ImmutableString, FnPtr, Array, Unit);
|
||||
|
||||
#[cfg(not(feature = "only_i32"))]
|
||||
#[cfg(not(feature = "only_i64"))]
|
||||
{
|
||||
reg_functions!(lib += numbers; i8, u8, i16, u16, i32, i64, u32, u64);
|
||||
reg_pad!(lib, u8, i16, u16, i32, u32, i64, u64);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
reg_functions!(lib += num_128; i128, u128);
|
||||
reg_pad!(lib, i128, u128);
|
||||
}
|
||||
reg_functions!(lib += num_128; i128, u128);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
{
|
||||
reg_functions!(lib += float; f32, f64);
|
||||
reg_pad!(lib, f32, f64);
|
||||
}
|
||||
reg_functions!(lib += float; f32, f64);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
reg_functions!(lib += map; Map);
|
||||
|
||||
// Register array iterator
|
||||
lib.set_iter(
|
||||
@ -207,3 +198,6 @@ gen_array_functions!(num_128 => i128, u128);
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
gen_array_functions!(float => f32, f64);
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
gen_array_functions!(map => Map);
|
||||
|
@ -9,13 +9,13 @@ def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, {
|
||||
#[export_module]
|
||||
mod fn_ptr_functions {
|
||||
#[inline(always)]
|
||||
fn name(f: &mut FnPtr) -> ImmutableString {
|
||||
pub fn name(f: &mut FnPtr) -> ImmutableString {
|
||||
f.get_fn_name().clone()
|
||||
}
|
||||
|
||||
#[rhai_fn(get = "name")]
|
||||
#[inline(always)]
|
||||
fn name_prop(f: &mut FnPtr) -> ImmutableString {
|
||||
pub fn name_prop(f: &mut FnPtr) -> ImmutableString {
|
||||
name(f)
|
||||
}
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ macro_rules! gen_cmp_functions {
|
||||
}
|
||||
|
||||
macro_rules! reg_functions {
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => {
|
||||
$($mod_name.combine_flatten(exported_module!($root::$arg_type::functions));)*
|
||||
}
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||
$mod_name.combine_flatten(exported_module!($root::$arg_type::functions));
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:LogicPackage:"Logical operators.", lib, {
|
||||
|
@ -41,9 +41,9 @@ macro_rules! gen_conversion_functions {
|
||||
}
|
||||
|
||||
macro_rules! reg_functions {
|
||||
($mod_name:ident += $root:ident :: $func_name:ident ( $($arg_type:ident),+ ) ) => {
|
||||
$(set_exported_fn!($mod_name, stringify!($func_name), $root::$arg_type::$func_name);)*
|
||||
}
|
||||
($mod_name:ident += $root:ident :: $func_name:ident ( $($arg_type:ident),+ ) ) => { $(
|
||||
set_exported_fn!($mod_name, stringify!($func_name), $root::$arg_type::$func_name);
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, {
|
||||
|
@ -37,16 +37,16 @@ macro_rules! gen_functions {
|
||||
}
|
||||
|
||||
macro_rules! reg_print_functions {
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => {
|
||||
$(set_exported_fn!($mod_name, FN_TO_STRING, $root::$arg_type::to_string_func);)*
|
||||
$(set_exported_fn!($mod_name, KEYWORD_PRINT, $root::$arg_type::to_string_func);)*
|
||||
}
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||
set_exported_fn!($mod_name, FN_TO_STRING, $root::$arg_type::to_string_func);
|
||||
set_exported_fn!($mod_name, KEYWORD_PRINT, $root::$arg_type::to_string_func);
|
||||
)* }
|
||||
}
|
||||
|
||||
macro_rules! reg_debug_functions {
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => {
|
||||
$(set_exported_fn!($mod_name, KEYWORD_DEBUG, $root::$arg_type::to_string_func);)*
|
||||
}
|
||||
($mod_name:ident += $root:ident ; $($arg_type:ident),+) => { $(
|
||||
set_exported_fn!($mod_name, KEYWORD_DEBUG, $root::$arg_type::to_string_func);
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:BasicStringPackage:"Basic string utilities, including printing.", lib, {
|
||||
|
@ -38,10 +38,10 @@ macro_rules! gen_concat_functions {
|
||||
}
|
||||
|
||||
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);)*
|
||||
}
|
||||
($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);
|
||||
)* }
|
||||
}
|
||||
|
||||
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
|
||||
|
@ -66,7 +66,7 @@ mod time_functions {
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw, name = "-")]
|
||||
fn time_diff(ts1: Instant, ts2: Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
pub fn time_diff(ts1: Instant, ts2: Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
{
|
||||
Ok(if ts2 > ts1 {
|
||||
|
Loading…
Reference in New Issue
Block a user