diff --git a/gdnative-core/src/export/class_builder.rs b/gdnative-core/src/export/class_builder.rs index 45315d1a8..fb1f2c2f4 100644 --- a/gdnative-core/src/export/class_builder.rs +++ b/gdnative-core/src/export/class_builder.rs @@ -30,11 +30,11 @@ //! For full examples, see [`examples`](https://github.com/godot-rust/godot-rust/tree/master/examples) //! in the godot-rust repository. -use crate::core_types::GodotString; use std::ffi::CString; use std::marker::PhantomData; use std::ptr; +use crate::core_types::{GodotString, VariantType}; use crate::export::*; use crate::object::NewRef; use crate::private::get_api; @@ -199,13 +199,13 @@ impl ClassBuilder { let mut sys_args = args_and_hints .iter() - .map(|(arg, hint_string)| sys::godot_signal_argument { - name: arg.name.to_sys(), - type_: arg.default.get_type() as i32, - hint: arg.export_info.hint_kind, + .map(|(param, hint_string)| sys::godot_signal_argument { + name: param.name.to_sys(), + type_: Self::get_param_type(param) as i32, + hint: param.export_info.hint_kind, hint_string: hint_string.to_sys(), - usage: arg.usage.to_sys(), - default_value: arg.default.to_sys(), + usage: param.usage.to_sys(), + default_value: param.default.to_sys(), }) .collect::>(); @@ -223,6 +223,16 @@ impl ClassBuilder { } } + /// Returns the declared parameter type, or the default value's type, or Nil (in that order) + fn get_param_type(arg: &SignalParam) -> VariantType { + let export_type = arg.export_info.variant_type; + if export_type != VariantType::Nil { + export_type + } else { + arg.default.get_type() + } + } + pub(crate) fn add_method(&self, method: ScriptMethod) { let method_name = CString::new(method.name).unwrap();