Move if_def_fn into CorePackage.
This commit is contained in:
@@ -4,9 +4,34 @@ use super::iter_basic::BasicIteratorPackage;
|
||||
use super::logic::LogicPackage;
|
||||
use super::string_basic::BasicStringPackage;
|
||||
|
||||
use crate::def_package;
|
||||
use crate::fn_native::{CallableFunction, FnCallArgs};
|
||||
use crate::stdlib::{any::TypeId, iter::empty};
|
||||
use crate::{
|
||||
calc_script_fn_hash, def_package, FnAccess, FnNamespace, ImmutableString, NativeCallContext,
|
||||
INT,
|
||||
};
|
||||
|
||||
def_package!(crate:CorePackage:"_Core_ package containing basic facilities.", lib, {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
{
|
||||
let f = |ctx: NativeCallContext, args: &mut FnCallArgs| {
|
||||
let num_params = args[1].clone().cast::<INT>();
|
||||
let fn_name = args[0].as_str().unwrap();
|
||||
|
||||
Ok(if num_params < 0 {
|
||||
false.into()
|
||||
} else {
|
||||
let hash_script = calc_script_fn_hash(empty(), fn_name, num_params as usize);
|
||||
ctx.engine().has_override(ctx.mods, ctx.lib, 0, hash_script, true).into()
|
||||
})
|
||||
};
|
||||
|
||||
lib.set_fn("is_def_fn", FnNamespace::Global, FnAccess::Public,
|
||||
Some(&["fn_name: &str", "num_params: INT"]),
|
||||
&[TypeId::of::<ImmutableString>(), TypeId::of::<INT>()],
|
||||
CallableFunction::from_method(Box::new(f)));
|
||||
}
|
||||
|
||||
ArithmeticPackage::init(lib);
|
||||
LogicPackage::init(lib);
|
||||
BasicStringPackage::init(lib);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::engine::{FN_TO_STRING, KEYWORD_DEBUG, KEYWORD_PRINT};
|
||||
use crate::engine::{KEYWORD_DEBUG, KEYWORD_PRINT};
|
||||
use crate::plugin::*;
|
||||
use crate::stdlib::{
|
||||
fmt::{Debug, Display},
|
||||
@@ -32,7 +32,7 @@ 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, "to_string", $root::$arg_type::to_string_func);
|
||||
set_exported_fn!($mod_name, KEYWORD_PRINT, $root::$arg_type::to_string_func);
|
||||
)* }
|
||||
}
|
||||
|
Reference in New Issue
Block a user