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

View File

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

View File

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