Change output of AST::iter_functions.

This commit is contained in:
Stephen Chung
2020-12-12 16:31:13 +08:00
parent dbdb8f43b7
commit 1087c338bd
4 changed files with 27 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ pub struct ScriptFnDef {
pub params: StaticVec<ImmutableString>,
/// Access to external variables.
#[cfg(not(feature = "no_closure"))]
pub externals: crate::stdlib::collections::HashSet<ImmutableString>,
pub externals: Vec<ImmutableString>,
}
impl fmt::Display for ScriptFnDef {
@@ -501,8 +501,18 @@ impl AST {
#[inline(always)]
pub fn iter_functions<'a>(
&'a self,
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &ScriptFnDef)> + 'a {
self.functions.iter_script_fn()
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &[ImmutableString])> + 'a {
self.functions
.iter_script_fn()
.map(|(namespace, access, name, num_params, fn_def)| {
(
namespace,
access,
name,
num_params,
fn_def.params.as_slice(),
)
})
}
/// Clear all function definitions in the [`AST`].
#[cfg(not(feature = "no_function"))]

View File

@@ -539,7 +539,7 @@ impl Engine {
if !func.externals.is_empty() {
captured
.into_iter()
.filter(|(name, _, _)| func.externals.contains(name.as_ref()))
.filter(|(name, _, _)| func.externals.iter().any(|ex| ex == name))
.for_each(|(name, value, _)| {
// Consume the scope values.
scope.push_dynamic(name, value);