Skip to content

Commit

Permalink
fix: update param info if they do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ltabis committed Mar 24, 2024
1 parent 55da3b1 commit 208f4cb
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,24 +400,34 @@ impl FuncRegistration {
{
#[cfg(feature = "metadata")]
{
let mut param_type_names = FUNC::param_names()
.iter()
.map(|ty| format!("_: {}", engine.format_param_type(ty)))
.collect::<crate::FnArgsVec<_>>();

if FUNC::return_type() != TypeId::of::<()>() {
param_type_names.push(engine.format_param_type(FUNC::return_type_name()).into());
}
// Do not update parameter informations if `with_params_info` was called previously.
if self.metadata.params_info.is_empty() {
let mut param_type_names = FUNC::param_names()
.iter()
.map(|ty| format!("_: {}", engine.format_param_type(ty)))
.collect::<crate::FnArgsVec<_>>();

if FUNC::return_type() != TypeId::of::<()>() {
param_type_names
.push(engine.format_param_type(FUNC::return_type_name()).into());
}

let param_type_names = param_type_names
.iter()
.map(String::as_str)
.collect::<crate::FnArgsVec<_>>();
let param_type_names = param_type_names
.iter()
.map(String::as_str)
.collect::<crate::FnArgsVec<_>>();

self.with_params_info(param_type_names)
.in_global_namespace()
.set_into_module(engine.global_namespace_mut(), func)
self.with_params_info(param_type_names)
} else {
self
}
// Duplicate of code without metadata feature because it would
// require to set self as mut, which would trigger a warning without
// the metadata feature.
.in_global_namespace()
.set_into_module(engine.global_namespace_mut(), func)
}

#[cfg(not(feature = "metadata"))]
self.in_global_namespace()
.set_into_module(engine.global_namespace_mut(), func)
Expand Down

0 comments on commit 208f4cb

Please sign in to comment.