Add FnPtr to standard packages.

This commit is contained in:
Stephen Chung 2020-08-03 23:11:08 +08:00
parent 3fc35c4f87
commit e1a70fe958
3 changed files with 8 additions and 6 deletions

View File

@ -3,6 +3,7 @@
use crate::any::{Dynamic, Variant}; use crate::any::{Dynamic, Variant};
use crate::def_package; use crate::def_package;
use crate::engine::{Array, Engine}; use crate::engine::{Array, Engine};
use crate::fn_native::FnPtr;
use crate::module::{FuncReturn, Module}; use crate::module::{FuncReturn, Module};
use crate::parser::{ImmutableString, INT}; use crate::parser::{ImmutableString, INT};
@ -83,9 +84,9 @@ macro_rules! reg_pad {
} }
def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, { def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
reg_op!(lib, "push", push, INT, bool, char, ImmutableString, Array, ()); reg_op!(lib, "push", push, INT, bool, char, ImmutableString, FnPtr, Array, ());
reg_pad!(lib, "pad", pad, INT, bool, char, ImmutableString, Array, ()); reg_pad!(lib, "pad", pad, INT, bool, char, ImmutableString, FnPtr, Array, ());
reg_tri!(lib, "insert", ins, INT, bool, char, ImmutableString, Array, ()); reg_tri!(lib, "insert", ins, INT, bool, char, ImmutableString, FnPtr, Array, ());
lib.set_fn_2_mut("append", |x: &mut Array, y: Array| { lib.set_fn_2_mut("append", |x: &mut Array, y: Array| {
x.extend(y); x.extend(y);

View File

@ -21,7 +21,7 @@ fn to_debug<T: Debug>(x: &mut T) -> FuncReturn<ImmutableString> {
Ok(format!("{:?}", x).into()) Ok(format!("{:?}", x).into())
} }
fn to_string<T: Display>(x: &mut T) -> FuncReturn<ImmutableString> { fn to_string<T: Display>(x: &mut T) -> FuncReturn<ImmutableString> {
Ok(format!("{}", x).into()) Ok(x.to_string().into())
} }
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
fn format_map(x: &mut Map) -> FuncReturn<ImmutableString> { fn format_map(x: &mut Map) -> FuncReturn<ImmutableString> {

View File

@ -1,6 +1,7 @@
use crate::any::Dynamic; use crate::any::Dynamic;
use crate::def_package; use crate::def_package;
use crate::engine::Engine; use crate::engine::Engine;
use crate::fn_native::FnPtr;
use crate::module::{FuncReturn, Module}; use crate::module::{FuncReturn, Module};
use crate::parser::{ImmutableString, INT}; use crate::parser::{ImmutableString, INT};
use crate::utils::StaticVec; use crate::utils::StaticVec;
@ -88,10 +89,10 @@ macro_rules! reg_op {
} }
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, { def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
reg_op!(lib, "+", append, INT, bool, char); reg_op!(lib, "+", append, INT, bool, char, FnPtr);
lib.set_fn_2( "+", |x: ImmutableString, _: ()| Ok(x)); lib.set_fn_2( "+", |x: ImmutableString, _: ()| Ok(x));
reg_op!(lib, "+", prepend, INT, bool, char); reg_op!(lib, "+", prepend, INT, bool, char, FnPtr);
lib.set_fn_2("+", |_: (), y: ImmutableString| Ok(y)); lib.set_fn_2("+", |_: (), y: ImmutableString| Ok(y));
if cfg!(not(feature = "only_i32")) && cfg!(not(feature = "only_i64")) { if cfg!(not(feature = "only_i32")) && cfg!(not(feature = "only_i64")) {