Change output of AST::iter_functions.
This commit is contained in:
parent
dbdb8f43b7
commit
1087c338bd
@ -15,6 +15,7 @@ Breaking changes
|
|||||||
|
|
||||||
* `Engine::on_progress` now takes `u64` instead of `&u64`.
|
* `Engine::on_progress` now takes `u64` instead of `&u64`.
|
||||||
* The closure for `Engine::on_debug` now takes an additional `Position` parameter.
|
* The closure for `Engine::on_debug` now takes an additional `Position` parameter.
|
||||||
|
* `AST::iter_functions` returns a slice of parameter names instead of the internal `ScriptFnDef`.
|
||||||
|
|
||||||
Enhancements
|
Enhancements
|
||||||
------------
|
------------
|
||||||
|
@ -144,7 +144,18 @@ fn main() {
|
|||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
main_ast
|
main_ast
|
||||||
.iter_functions()
|
.iter_functions()
|
||||||
.for_each(|(_, _, _, _, f)| println!("{}", f));
|
.for_each(|(_, access, name, _, params)| {
|
||||||
|
println!(
|
||||||
|
"{}{}({}) -> Dynamic",
|
||||||
|
if access.is_private() { "private " } else { "" },
|
||||||
|
name,
|
||||||
|
params
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.as_str())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
continue;
|
continue;
|
||||||
|
16
src/ast.rs
16
src/ast.rs
@ -82,7 +82,7 @@ pub struct ScriptFnDef {
|
|||||||
pub params: StaticVec<ImmutableString>,
|
pub params: StaticVec<ImmutableString>,
|
||||||
/// Access to external variables.
|
/// Access to external variables.
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
pub externals: crate::stdlib::collections::HashSet<ImmutableString>,
|
pub externals: Vec<ImmutableString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ScriptFnDef {
|
impl fmt::Display for ScriptFnDef {
|
||||||
@ -501,8 +501,18 @@ impl AST {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn iter_functions<'a>(
|
pub fn iter_functions<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &ScriptFnDef)> + 'a {
|
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &[ImmutableString])> + 'a {
|
||||||
self.functions.iter_script_fn()
|
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`].
|
/// Clear all function definitions in the [`AST`].
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
@ -539,7 +539,7 @@ impl Engine {
|
|||||||
if !func.externals.is_empty() {
|
if !func.externals.is_empty() {
|
||||||
captured
|
captured
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(name, _, _)| func.externals.contains(name.as_ref()))
|
.filter(|(name, _, _)| func.externals.iter().any(|ex| ex == name))
|
||||||
.for_each(|(name, value, _)| {
|
.for_each(|(name, value, _)| {
|
||||||
// Consume the scope values.
|
// Consume the scope values.
|
||||||
scope.push_dynamic(name, value);
|
scope.push_dynamic(name, value);
|
||||||
|
Loading…
Reference in New Issue
Block a user