Implement function pointers.
This commit is contained in:
8
src/packages/fn_basic.rs
Normal file
8
src/packages/fn_basic.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use crate::def_package;
|
||||
use crate::fn_native::FnPtr;
|
||||
|
||||
def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, {
|
||||
lib.set_fn_1_mut("name", |f: &mut FnPtr| Ok(f.get_fn_name().clone()));
|
||||
lib.set_getter_fn("name", |f: &mut FnPtr| Ok(f.get_fn_name().clone()));
|
||||
|
||||
});
|
@@ -9,6 +9,7 @@ use crate::stdlib::any::TypeId;
|
||||
pub(crate) mod arithmetic;
|
||||
mod array_basic;
|
||||
mod eval;
|
||||
mod fn_basic;
|
||||
mod iter_basic;
|
||||
mod logic;
|
||||
mod map_basic;
|
||||
@@ -23,6 +24,8 @@ pub use arithmetic::ArithmeticPackage;
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub use array_basic::BasicArrayPackage;
|
||||
pub use eval::EvalPackage;
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub use fn_basic::BasicFnPackage;
|
||||
pub use iter_basic::BasicIteratorPackage;
|
||||
pub use logic::LogicPackage;
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use super::arithmetic::ArithmeticPackage;
|
||||
use super::fn_basic::BasicFnPackage;
|
||||
use super::iter_basic::BasicIteratorPackage;
|
||||
use super::logic::LogicPackage;
|
||||
use super::string_basic::BasicStringPackage;
|
||||
@@ -10,4 +11,5 @@ def_package!(crate:CorePackage:"_Core_ package containing basic facilities.", li
|
||||
LogicPackage::init(lib);
|
||||
BasicStringPackage::init(lib);
|
||||
BasicIteratorPackage::init(lib);
|
||||
BasicFnPackage::init(lib);
|
||||
});
|
||||
|
@@ -1,5 +1,6 @@
|
||||
use crate::def_package;
|
||||
use crate::engine::{FN_TO_STRING, KEYWORD_DEBUG, KEYWORD_PRINT};
|
||||
use crate::fn_native::FnPtr;
|
||||
use crate::module::FuncReturn;
|
||||
use crate::parser::{ImmutableString, INT};
|
||||
|
||||
@@ -34,8 +35,9 @@ macro_rules! reg_op {
|
||||
}
|
||||
|
||||
def_package!(crate:BasicStringPackage:"Basic string utilities, including printing.", lib, {
|
||||
reg_op!(lib, KEYWORD_PRINT, to_string, INT, bool, char);
|
||||
reg_op!(lib, FN_TO_STRING, to_string, INT, bool, char);
|
||||
reg_op!(lib, KEYWORD_PRINT, to_string, INT, bool, char, FnPtr);
|
||||
reg_op!(lib, FN_TO_STRING, to_string, INT, bool, char, FnPtr);
|
||||
lib.set_fn_1_mut(KEYWORD_DEBUG, |f: &mut FnPtr| Ok(f.to_string()));
|
||||
|
||||
lib.set_fn_0(KEYWORD_PRINT, || Ok("".to_string()));
|
||||
lib.set_fn_1(KEYWORD_PRINT, |_: ()| Ok("".to_string()));
|
||||
|
Reference in New Issue
Block a user