diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c779c63..3d2733a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Bug fixes * Missing `to_hex`, `to_octal` and `to_binary` for `i128` and `u128` are added. * `remove` for arrays and BLOB's now treat negative index correctly. * `parse_int` now works properly for negative numbers. +* `Engine::gen_fn_signatures` now generates signatures for external packages registered via `Engine::register_global_module`. Enhancements ------------ diff --git a/src/api/register.rs b/src/api/register.rs index 07fe973b..b489a2b8 100644 --- a/src/api/register.rs +++ b/src/api/register.rs @@ -1027,7 +1027,8 @@ impl Engine { /// Functions from the following sources are included, in order: /// 1) Functions registered into the global namespace /// 2) Functions in registered sub-modules - /// 3) Functions in packages (optional) + /// 3) Functions in registered packages + /// 4) Functions in standard packages (optional) #[cfg(feature = "metadata")] #[inline] #[must_use] @@ -1040,14 +1041,13 @@ impl Engine { signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f))) }); - if include_packages { - signatures.extend( - self.global_modules - .iter() - .skip(1) - .flat_map(|m| m.gen_fn_signatures()), - ); - } + signatures.extend( + self.global_modules + .iter() + .skip(1) + .filter(|m| !m.internal && (include_packages || !m.standard)) + .flat_map(|m| m.gen_fn_signatures()), + ); signatures } diff --git a/src/module/mod.rs b/src/module/mod.rs index 8181edce..4381c530 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -182,11 +182,6 @@ impl FuncInfo { .collect(); sig.push_str(¶ms.join(", ")); sig.push(')'); - - if !return_type.is_empty() { - sig.push_str(" -> "); - sig.push_str(&return_type); - } } else { for x in 0..self.metadata.params { sig.push('_'); @@ -194,17 +189,12 @@ impl FuncInfo { sig.push_str(", "); } } - sig.push(')'); + } - if !self.func.is_script() { - sig.push(')'); - - if !return_type.is_empty() { - sig.push_str(" -> "); - sig.push_str(&return_type); - } - } + if !self.func.is_script() && !return_type.is_empty() { + sig.push_str(" -> "); + sig.push_str(&return_type); } sig @@ -596,7 +586,7 @@ impl Module { #[cfg(feature = "metadata")] params_info, #[cfg(feature = "metadata")] - return_type: "Dynamic".into(), + return_type: "".into(), #[cfg(feature = "metadata")] comments: None, }, diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 3e1919e0..ded1e362 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -196,11 +196,12 @@ impl Engine { /// 1) Functions defined in an [`AST`][crate::AST] /// 2) Functions registered into the global namespace /// 3) Functions in static modules - /// 4) Functions in global modules (optional) + /// 4) Functions in registered global packages + /// 5) Functions in standard packages (optional) pub fn gen_fn_metadata_with_ast_to_json( &self, ast: &AST, - include_global: bool, + include_packages: bool, ) -> serde_json::Result { let _ast = ast; let mut global = ModuleMetadata::new(); @@ -211,14 +212,20 @@ impl Engine { self.global_modules .iter() - .take(if include_global { usize::MAX } else { 1 }) + .filter(|m| include_packages || !m.standard) .flat_map(|m| m.iter_fn()) - .for_each(|f| global.functions.push(f.into())); + .for_each(|f| { + let mut meta: FnMetadata = f.into(); + meta.namespace = FnNamespace::Global; + global.functions.push(meta); + }); #[cfg(not(feature = "no_function"))] - _ast.shared_lib() - .iter_fn() - .for_each(|f| global.functions.push(f.into())); + _ast.shared_lib().iter_fn().for_each(|f| { + let mut meta: FnMetadata = f.into(); + meta.namespace = FnNamespace::Global; + global.functions.push(meta); + }); global.functions.sort(); @@ -233,7 +240,7 @@ impl Engine { /// 2) Functions in static modules /// 3) Functions in global modules (optional) #[inline(always)] - pub fn gen_fn_metadata_to_json(&self, include_global: bool) -> serde_json::Result { - self.gen_fn_metadata_with_ast_to_json(&AST::empty(), include_global) + pub fn gen_fn_metadata_to_json(&self, include_packages: bool) -> serde_json::Result { + self.gen_fn_metadata_with_ast_to_json(&AST::empty(), include_packages) } }