Add functions to iterate script function definitions.
This commit is contained in:
parent
12e9a8567d
commit
b8aeaa84de
@ -25,6 +25,7 @@ New features
|
||||
* Plugins support via procedural macros.
|
||||
* Scripted functions are allowed in packages.
|
||||
* `parse_int` and `parse_float` functions.
|
||||
* `AST::iter_functions` and `Module::iter_script_fn_info` to iterate functions.
|
||||
|
||||
|
||||
Version 0.18.3
|
||||
|
@ -1124,6 +1124,14 @@ impl Module {
|
||||
.map(|f| f.get_shared_fn_def())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn iter_script_fn_info(&self, action: impl Fn(FnAccess, &str, usize)) {
|
||||
self.functions.iter().for_each(|(_, (_, _, _, v))| match v {
|
||||
Func::Script(ref f) => action(f.access, f.name.as_str(), f.params.len()),
|
||||
_ => (),
|
||||
});
|
||||
}
|
||||
|
||||
/// Create a new `Module` by evaluating an `AST`.
|
||||
///
|
||||
/// # Examples
|
||||
@ -1493,13 +1501,13 @@ mod file {
|
||||
#[cfg(feature = "sync")]
|
||||
let c = self.cache.read().unwrap();
|
||||
|
||||
match c.get(&file_path) {
|
||||
Some(ast) => (
|
||||
if let Some(ast) = c.get(&file_path) {
|
||||
(
|
||||
Module::eval_ast_as_new(scope, ast, engine)
|
||||
.map_err(|err| err.new_position(pos))?,
|
||||
None,
|
||||
),
|
||||
None => {
|
||||
)
|
||||
} else {
|
||||
// Load the file and compile it if not found
|
||||
let ast = engine
|
||||
.compile_file(file_path.clone())
|
||||
@ -1511,7 +1519,6 @@ mod file {
|
||||
Some(ast),
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(ast) = ast {
|
||||
|
@ -299,6 +299,12 @@ impl AST {
|
||||
self.1.retain_functions(filter);
|
||||
}
|
||||
|
||||
/// Iterate through all functions
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn iter_functions(&self, action: impl Fn(FnAccess, &str, usize)) {
|
||||
self.1.iter_script_fn_info(action);
|
||||
}
|
||||
|
||||
/// Clear all function definitions in the `AST`.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn clear_functions(&mut self) {
|
||||
|
Loading…
Reference in New Issue
Block a user