From 07b6a03d77c4dfc7400c44fe40308b3f7a89d1cd Mon Sep 17 00:00:00 2001 From: David Snopek Date: Sat, 1 Jun 2024 08:45:23 -0500 Subject: [PATCH 1/5] Explicitly refer to `godot` namespace in `GDREGISTER_*_CLASS()` macros (cherry picked from commit 246a803954b288138f1ef6b3536321098b3b3675) --- include/godot_cpp/core/class_db.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index 9cc24b57..87a40895 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -338,10 +338,10 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p return bind; } -#define GDREGISTER_CLASS(m_class) ClassDB::register_class(); -#define GDREGISTER_VIRTUAL_CLASS(m_class) ClassDB::register_class(true); -#define GDREGISTER_ABSTRACT_CLASS(m_class) ClassDB::register_abstract_class(); -#define GDREGISTER_INTERNAL_CLASS(m_class) ClassDB::register_internal_class(); +#define GDREGISTER_CLASS(m_class) ::godot::ClassDB::register_class(); +#define GDREGISTER_VIRTUAL_CLASS(m_class) ::godot::ClassDB::register_class(true); +#define GDREGISTER_ABSTRACT_CLASS(m_class) ::godot::ClassDB::register_abstract_class(); +#define GDREGISTER_INTERNAL_CLASS(m_class) ::godot::ClassDB::register_internal_class(); } // namespace godot From b81b0599f997b580f84ae55bdcdcba976f684935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Hoz=C3=A1k?= <5235838+richardhozak@users.noreply.github.com> Date: Sun, 2 Jun 2024 21:47:51 +0200 Subject: [PATCH 2/5] Fix warnings emitted with -Wall (cherry picked from commit 8c6cc1ec155bc0c5eee389e755e188e46e0f064d) --- src/core/class_db.cpp | 2 +- src/core/object.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/class_db.cpp b/src/core/class_db.cpp index 2f82a352..23ad94f7 100644 --- a/src/core/class_db.cpp +++ b/src/core/class_db.cpp @@ -388,7 +388,7 @@ void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) { { std::lock_guard lock(engine_singletons_mutex); singleton_objects.reserve(engine_singletons.size()); - for (const std::pair &pair : engine_singletons) { + for (const std::pair &pair : engine_singletons) { singleton_objects.push_back(pair.second); } } diff --git a/src/core/object.cpp b/src/core/object.cpp index d2e10ffb..410daf85 100644 --- a/src/core/object.cpp +++ b/src/core/object.cpp @@ -75,7 +75,7 @@ MethodInfo::operator Dictionary() const { dict["name"] = name; dict["args"] = internal::convert_property_list(arguments); Array da; - for (int i = 0; i < default_arguments.size(); i++) { + for (size_t i = 0; i < default_arguments.size(); i++) { da.push_back(default_arguments[i]); } dict["default_args"] = da; From 246fd4718c949e06250c97a3acdecfdbfeeeaffd Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 12 Jun 2024 08:18:52 -0500 Subject: [PATCH 3/5] Fix vararg methods forwarded to the `ClassDB` singleton (cherry picked from commit e04a26b2bc2edc64635f6b9bb0423f700e00b97a) --- binding_generator.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index bb1bc3e0..3a4de97e 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -1535,13 +1535,16 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us result.append("\t \\") for method in class_api["methods"]: - # ClassDBSingleton shouldn't have any static or vararg methods, but if some appear later, lets skip them. - if vararg: - continue + # ClassDBSingleton shouldn't have any static methods, but if some appear later, lets skip them. if "is_static" in method and method["is_static"]: continue - method_signature = "\tstatic " + vararg = "is_vararg" in method and method["is_vararg"] + if vararg: + method_signature = "\ttemplate static " + else: + method_signature = "\tstatic " + return_type = None if "return_type" in method: return_type = correct_type(method["return_type"].replace("ClassDBSingleton", "ClassDB"), None, False) @@ -1563,7 +1566,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us method_arguments = method["arguments"] method_signature += make_function_parameters( - method_arguments, include_default=True, for_builtin=True, is_vararg=False + method_arguments, include_default=True, for_builtin=True, is_vararg=vararg ) method_signature += ") { \\" @@ -1577,6 +1580,8 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us method_body += f"({return_type})" method_body += f'ClassDBSingleton::get_singleton()->{method["name"]}(' method_body += ", ".join(map(lambda x: escape_identifier(x["name"]), method_arguments)) + if vararg: + method_body += ", args..." method_body += "); \\" result.append(method_body) @@ -2224,9 +2229,9 @@ def make_varargs_template( args_array = f"\tstd::array variant_args {{ " for argument in method_arguments: if argument["type"] == "Variant": - args_array += argument["name"] + args_array += escape_identifier(argument["name"]) else: - args_array += f'Variant({argument["name"]})' + args_array += f'Variant({escape_identifier(argument["name"])})' args_array += ", " args_array += "Variant(args)... };" From a6e5caacf83486b0df48568895ed8e7ce8547126 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:57:23 +0200 Subject: [PATCH 4/5] Fix generating default values for `StringName` Cases other than `&""` were not processed correctly (cherry picked from commit 6cd6c8923a6e623776502a9245f48cfc5c5baf50) --- binding_generator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index 3a4de97e..cc5e6f33 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -2442,6 +2442,8 @@ def correct_default_value(value, type_name): return f"{type_name}()" if value.startswith("Array["): return f"{{}}" + if value.startswith("&"): + return value[1::] return value From c5204a2e8429ec7d7742c1d358a175c3fda7ce9d Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:17:33 +0200 Subject: [PATCH 5/5] Add default argument processing for `NodePath` (cherry picked from commit 37e7a6da0536d496e2e3773911fdf300a2c5522d) --- binding_generator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index cc5e6f33..95084922 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -2431,6 +2431,7 @@ def correct_default_value(value, type_name): "null": "nullptr", '""': "String()", '&""': "StringName()", + '^""': "NodePath()", "[]": "Array()", "{}": "Dictionary()", "Transform2D(1, 0, 0, 1, 0, 0)": "Transform2D()", # Default transform. @@ -2444,6 +2445,8 @@ def correct_default_value(value, type_name): return f"{{}}" if value.startswith("&"): return value[1::] + if value.startswith("^"): + return value[1::] return value