Merge pull request #113754 from dsnopek/gdextension-interface-json-tweaks

Tweaks to `gdextension_interface.json` format
This commit is contained in:
Rémi Verschelde 2025-12-09 17:17:38 +01:00
commit ee8b979d85
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 39 additions and 22 deletions

View File

@ -332,11 +332,13 @@
"name": "GDExtensionConstVariantPtr", "name": "GDExtensionConstVariantPtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionVariantPtr", "parent": "GDExtensionVariantPtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionUninitializedVariantPtr", "name": "GDExtensionUninitializedVariantPtr",
"kind": "handle" "kind": "handle",
"parent": "GDExtensionVariantPtr",
"is_uninitialized": true
}, },
{ {
"name": "GDExtensionStringNamePtr", "name": "GDExtensionStringNamePtr",
@ -346,11 +348,13 @@
"name": "GDExtensionConstStringNamePtr", "name": "GDExtensionConstStringNamePtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionStringNamePtr", "parent": "GDExtensionStringNamePtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionUninitializedStringNamePtr", "name": "GDExtensionUninitializedStringNamePtr",
"kind": "handle" "kind": "handle",
"parent": "GDExtensionStringNamePtr",
"is_uninitialized": true
}, },
{ {
"name": "GDExtensionStringPtr", "name": "GDExtensionStringPtr",
@ -360,11 +364,13 @@
"name": "GDExtensionConstStringPtr", "name": "GDExtensionConstStringPtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionStringPtr", "parent": "GDExtensionStringPtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionUninitializedStringPtr", "name": "GDExtensionUninitializedStringPtr",
"kind": "handle" "kind": "handle",
"parent": "GDExtensionStringPtr",
"is_uninitialized": true
}, },
{ {
"name": "GDExtensionObjectPtr", "name": "GDExtensionObjectPtr",
@ -374,12 +380,13 @@
"name": "GDExtensionConstObjectPtr", "name": "GDExtensionConstObjectPtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionObjectPtr", "parent": "GDExtensionObjectPtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionUninitializedObjectPtr", "name": "GDExtensionUninitializedObjectPtr",
"kind": "handle",
"parent": "GDExtensionObjectPtr", "parent": "GDExtensionObjectPtr",
"kind": "handle" "is_uninitialized": true
}, },
{ {
"name": "GDExtensionTypePtr", "name": "GDExtensionTypePtr",
@ -389,16 +396,18 @@
"name": "GDExtensionConstTypePtr", "name": "GDExtensionConstTypePtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionTypePtr", "parent": "GDExtensionTypePtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionUninitializedTypePtr", "name": "GDExtensionUninitializedTypePtr",
"kind": "handle" "kind": "handle",
"parent": "GDExtensionTypePtr",
"is_uninitialized": true
}, },
{ {
"name": "GDExtensionMethodBindPtr", "name": "GDExtensionMethodBindPtr",
"kind": "handle", "kind": "handle",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionInt", "name": "GDExtensionInt",
@ -423,7 +432,7 @@
"name": "GDExtensionConstRefPtr", "name": "GDExtensionConstRefPtr",
"kind": "handle", "kind": "handle",
"parent": "GDExtensionRefPtr", "parent": "GDExtensionRefPtr",
"const": true "is_const": true
}, },
{ {
"name": "GDExtensionCallErrorType", "name": "GDExtensionCallErrorType",
@ -573,7 +582,7 @@
}, },
{ {
"name": "p_argument_count", "name": "p_argument_count",
"type": "int" "type": "int32_t"
} }
] ]
}, },
@ -759,7 +768,7 @@
}, },
{ {
"name": "p_argument_count", "name": "p_argument_count",
"type": "int" "type": "int32_t"
} }
] ]
}, },
@ -1864,6 +1873,7 @@
{ {
"name": "GDExtensionClassMethodFlags", "name": "GDExtensionClassMethodFlags",
"kind": "enum", "kind": "enum",
"is_bitfield": true,
"values": [ "values": [
{ {
"name": "GDEXTENSION_METHOD_FLAG_NORMAL", "name": "GDEXTENSION_METHOD_FLAG_NORMAL",
@ -6815,14 +6825,14 @@
}, },
{ {
"name": "p_elements", "name": "p_elements",
"type": "int", "type": "int32_t",
"description": [ "description": [
"The number of element needed in the group." "The number of element needed in the group."
] ]
}, },
{ {
"name": "p_tasks", "name": "p_tasks",
"type": "int", "type": "int32_t",
"description": [ "description": [
"The number of tasks needed in the group." "The number of tasks needed in the group."
] ]

View File

@ -69,6 +69,9 @@
}, },
"then": { "then": {
"properties": { "properties": {
"is_bitfield": {
"type": "boolean"
},
"values": { "values": {
"type": "array", "type": "array",
"items": { "items": {
@ -106,7 +109,10 @@
"parent": { "parent": {
"type": "string" "type": "string"
}, },
"const": { "is_const": {
"type": "boolean"
},
"is_uninitialized": {
"type": "boolean" "type": "boolean"
} }
} }

View File

@ -97,7 +97,7 @@ void GDExtensionInterfaceHeaderGenerator::generate_gdextension_interface_header(
} }
String kind = type_dict["kind"]; String kind = type_dict["kind"];
if (kind == "handle") { if (kind == "handle") {
type_dict["type"] = type_dict.get("const", false) ? "const void*" : "void*"; type_dict["type"] = type_dict.get("is_const", false) ? "const void*" : "void*";
write_simple_type(fa, type_dict); write_simple_type(fa, type_dict);
} else if (kind == "alias") { } else if (kind == "alias") {
write_simple_type(fa, type_dict); write_simple_type(fa, type_dict);

View File

@ -6,7 +6,6 @@ import methods
BASE_TYPES = [ BASE_TYPES = [
"void", "void",
"int",
"int8_t", "int8_t",
"uint8_t", "uint8_t",
"int16_t", "int16_t",
@ -70,18 +69,20 @@ extern "C" {
write_doc(file, type["description"]) write_doc(file, type["description"])
if kind == "handle": if kind == "handle":
check_allowed_keys(type, ["name", "kind"], ["const", "parent", "description", "deprecated"]) check_allowed_keys(
type, ["name", "kind"], ["is_const", "is_uninitialized", "parent", "description", "deprecated"]
)
if "parent" in type and type["parent"] not in handles: if "parent" in type and type["parent"] not in handles:
raise UnknownTypeError(type["parent"], type["name"]) raise UnknownTypeError(type["parent"], type["name"])
# @todo In the future, let's write these as `struct *` so the compiler can help us with type checking. # @todo In the future, let's write these as `struct *` so the compiler can help us with type checking.
type["type"] = "void*" if not type.get("const", False) else "const void*" type["type"] = "void*" if not type.get("is_const", False) else "const void*"
write_simple_type(file, type) write_simple_type(file, type)
handles.append(type["name"]) handles.append(type["name"])
elif kind == "alias": elif kind == "alias":
check_allowed_keys(type, ["name", "kind", "type"], ["description", "deprecated"]) check_allowed_keys(type, ["name", "kind", "type"], ["description", "deprecated"])
write_simple_type(file, type) write_simple_type(file, type)
elif kind == "enum": elif kind == "enum":
check_allowed_keys(type, ["name", "kind", "values"], ["description", "deprecated"]) check_allowed_keys(type, ["name", "kind", "values"], ["is_bitfield", "description", "deprecated"])
write_enum_type(file, type) write_enum_type(file, type)
elif kind == "function": elif kind == "function":
check_allowed_keys(type, ["name", "kind", "return_value", "arguments"], ["description", "deprecated"]) check_allowed_keys(type, ["name", "kind", "return_value", "arguments"], ["description", "deprecated"])