Remove support for script-line native functions.

This commit is contained in:
Stephen Chung 2020-10-13 14:40:02 +08:00
parent 6db412815b
commit 28697e0380
2 changed files with 9 additions and 42 deletions

View File

@ -193,11 +193,9 @@ impl Engine {
// Search for the native function // Search for the native function
// First search registered functions (can override packages) // First search registered functions (can override packages)
// Then search packages // Then search packages
let func = self let func = //lib.get_fn(hash_fn, pub_only)
.global_module self.global_module.get_fn(hash_fn, pub_only)
.get_fn(hash_fn, pub_only) .or_else(|| self.packages.get_fn(hash_fn, pub_only));
.or_else(|| lib.get_fn(hash_fn, pub_only))
.or_else(|| self.packages.get_fn(hash_fn, pub_only));
if let Some(func) = func { if let Some(func) = func {
assert!(func.is_native()); assert!(func.is_native());
@ -462,9 +460,9 @@ impl Engine {
// First check script-defined functions // First check script-defined functions
lib.contains_fn(hash_script, pub_only) lib.contains_fn(hash_script, pub_only)
|| lib.contains_fn(hash_fn, pub_only) //|| lib.contains_fn(hash_fn, pub_only)
// Then check registered functions // Then check registered functions
|| self.global_module.contains_fn(hash_script, pub_only) //|| self.global_module.contains_fn(hash_script, pub_only)
|| self.global_module.contains_fn(hash_fn, pub_only) || self.global_module.contains_fn(hash_fn, pub_only)
// Then check packages // Then check packages
|| self.packages.contains_fn(hash_script, pub_only) || self.packages.contains_fn(hash_script, pub_only)
@ -547,15 +545,14 @@ impl Engine {
// Script-like function found // Script-like function found
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
_ if self.global_module.contains_fn(hash_script, pub_only) _ if lib.contains_fn(hash_script, pub_only)
|| lib.contains_fn(hash_script, pub_only) //|| self.global_module.contains_fn(hash_script, pub_only)
|| self.packages.contains_fn(hash_script, pub_only) => || self.packages.contains_fn(hash_script, pub_only) =>
{ {
// Get function // Get function
let func = self let func = lib
.global_module
.get_fn(hash_script, pub_only) .get_fn(hash_script, pub_only)
.or_else(|| lib.get_fn(hash_script, pub_only)) //.or_else(|| self.global_module.get_fn(hash_script, pub_only))
.or_else(|| self.packages.get_fn(hash_script, pub_only)) .or_else(|| self.packages.get_fn(hash_script, pub_only))
.unwrap(); .unwrap();

View File

@ -549,36 +549,6 @@ impl Module {
) )
} }
/// Set a raw function but with a signature that is a scripted function (meaning that the types
/// are not determined), but the implementation is in Rust.
#[cfg(not(feature = "no_function"))]
#[cfg(not(feature = "no_module"))]
#[inline]
#[allow(dead_code)]
pub(crate) fn set_raw_fn_as_scripted(
&mut self,
name: impl Into<String>,
num_params: usize,
func: impl Fn(&Engine, &Module, &mut [&mut Dynamic]) -> FuncReturn<Dynamic> + SendSync + 'static,
) -> u64 {
// None + function name + number of arguments.
let name = name.into();
let hash_script = calc_fn_hash(empty(), &name, num_params, empty());
let f = move |engine: &Engine, lib: &Module, args: &mut FnCallArgs| func(engine, lib, args);
self.functions.insert(
hash_script,
(
name,
FnAccess::Public,
num_params,
None,
CallableFunction::from_pure(Box::new(f)),
),
);
self.indexed = false;
hash_script
}
/// Set a Rust function taking no parameters into the module, returning a hash key. /// Set a Rust function taking no parameters into the module, returning a hash key.
/// ///
/// If there is a similar existing Rust function, it is replaced. /// If there is a similar existing Rust function, it is replaced.