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.
|
* Plugins support via procedural macros.
|
||||||
* Scripted functions are allowed in packages.
|
* Scripted functions are allowed in packages.
|
||||||
* `parse_int` and `parse_float` functions.
|
* `parse_int` and `parse_float` functions.
|
||||||
|
* `AST::iter_functions` and `Module::iter_script_fn_info` to iterate functions.
|
||||||
|
|
||||||
|
|
||||||
Version 0.18.3
|
Version 0.18.3
|
||||||
|
@ -1124,6 +1124,14 @@ impl Module {
|
|||||||
.map(|f| f.get_shared_fn_def())
|
.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`.
|
/// Create a new `Module` by evaluating an `AST`.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
@ -1493,24 +1501,23 @@ mod file {
|
|||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
let c = self.cache.read().unwrap();
|
let c = self.cache.read().unwrap();
|
||||||
|
|
||||||
match c.get(&file_path) {
|
if let Some(ast) = c.get(&file_path) {
|
||||||
Some(ast) => (
|
(
|
||||||
Module::eval_ast_as_new(scope, ast, engine)
|
Module::eval_ast_as_new(scope, ast, engine)
|
||||||
.map_err(|err| err.new_position(pos))?,
|
.map_err(|err| err.new_position(pos))?,
|
||||||
None,
|
None,
|
||||||
),
|
)
|
||||||
None => {
|
} else {
|
||||||
// Load the file and compile it if not found
|
// Load the file and compile it if not found
|
||||||
let ast = engine
|
let ast = engine
|
||||||
.compile_file(file_path.clone())
|
.compile_file(file_path.clone())
|
||||||
.map_err(|err| err.new_position(pos))?;
|
.map_err(|err| err.new_position(pos))?;
|
||||||
|
|
||||||
(
|
(
|
||||||
Module::eval_ast_as_new(scope, &ast, engine)
|
Module::eval_ast_as_new(scope, &ast, engine)
|
||||||
.map_err(|err| err.new_position(pos))?,
|
.map_err(|err| err.new_position(pos))?,
|
||||||
Some(ast),
|
Some(ast),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -299,6 +299,12 @@ impl AST {
|
|||||||
self.1.retain_functions(filter);
|
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`.
|
/// Clear all function definitions in the `AST`.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub fn clear_functions(&mut self) {
|
pub fn clear_functions(&mut self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user