Skip to content

Commit 8ad9cb0

Browse files
authored
Merge pull request #904 from godot-rust/feature/detect-required-virtuals
Detect whether virtual functions are required to override
2 parents 6e46fa4 + b1db236 commit 8ad9cb0

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

godot-codegen/src/models/domain_mapping.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ impl ClassMethod {
456456
FnQualifier::from_const_static(is_actually_const, method.is_static)
457457
};
458458

459+
// Since Godot 4.4, GDExtension advertises whether virtual methods have a default implementation or are required to be overridden.
460+
#[cfg(before_api = "4.4")]
461+
let is_virtual_required = special_cases::is_virtual_method_required(
462+
&class_name.rust_ty.to_string(),
463+
rust_method_name,
464+
);
465+
466+
#[cfg(since_api = "4.4")]
467+
let is_virtual_required = method.is_virtual
468+
&& method.is_required.unwrap_or_else(|| {
469+
panic!(
470+
"virtual method {}::{} lacks field `is_required`",
471+
class_name.rust_ty, rust_method_name
472+
);
473+
});
474+
459475
Some(Self {
460476
common: FunctionCommon {
461477
name: rust_method_name.to_string(),
@@ -464,10 +480,7 @@ impl ClassMethod {
464480
return_value: FnReturn::new(&method.return_value, ctx),
465481
is_vararg: method.is_vararg,
466482
is_private,
467-
is_virtual_required: special_cases::is_virtual_method_required(
468-
&class_name.rust_ty.to_string(),
469-
rust_method_name,
470-
),
483+
is_virtual_required,
471484
direction,
472485
},
473486
qualifier,

godot-codegen/src/models/json.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ pub struct JsonClassMethod {
220220
pub is_vararg: bool,
221221
pub is_static: bool,
222222
pub is_virtual: bool,
223+
#[cfg(since_api = "4.4")]
224+
pub is_required: Option<bool>, // Only virtual functions have this field.
223225
pub hash: Option<i64>,
224226
pub return_value: Option<JsonMethodReturn>,
225227
pub arguments: Option<Vec<JsonMethodArg>>,

godot-codegen/src/special_cases/special_cases.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ pub fn get_interface_extra_docs(trait_name: &str) -> Option<&'static str> {
389389
}
390390
}
391391

392+
#[cfg(before_api = "4.4")]
392393
pub fn is_virtual_method_required(class_name: &str, method: &str) -> bool {
393394
match (class_name, method) {
394395
("ScriptLanguageExtension", _) => method != "get_doc_comment_delimiters",

0 commit comments

Comments
 (0)