From b6ba0dca13c1cda5826f23abf203c2f05c0bee42 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sun, 23 Oct 2022 22:31:57 +0200 Subject: [PATCH] StringName is working fine with demo \o/ --- binding_generator.py | 16 ++++++++++++++-- include/godot_cpp/classes/wrapped.hpp | 10 +++++----- include/godot_cpp/core/class_db.hpp | 4 ++-- include/godot_cpp/core/method_bind.hpp | 2 +- src/core/class_db.cpp | 12 ++++++------ src/variant/variant.cpp | 2 +- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 33bd568..380033d 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -397,6 +397,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("") result.append("\tfriend class Variant;") + if class_name == "String": + result.append("\tfriend class StringName;") result.append("") result.append("\tstatic struct _MethodBindings {") @@ -439,6 +441,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("") result.append("\tstatic void init_bindings();") + result.append("\tstatic void _init_bindings_constructors_destructor();") result.append("") result.append("public:") @@ -675,7 +678,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result.append(f"{class_name}::_MethodBindings {class_name}::_method_bindings;") result.append("") - result.append(f"void {class_name}::init_bindings() {{") + result.append(f"void {class_name}::_init_bindings_constructors_destructor() {{") if "constructors" in builtin_api: for constructor in builtin_api["constructors"]: @@ -688,7 +691,16 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl f"\t_method_bindings.destructor = internal::gdn_interface->variant_get_ptr_destructor({enum_type_name});" ) - result.append(f"StringName __name;") + result.append("}") + + result.append(f"void {class_name}::init_bindings() {{") + + # StringName's constructor internally uses String, so it constructor must be ready ! + if class_name == "StringName": + result.append(f"\tString::_init_bindings_constructors_destructor();") + result.append(f"\t{class_name}::_init_bindings_constructors_destructor();") + + result.append(f"\tStringName __name;") if "methods" in builtin_api: for method in builtin_api["methods"]: diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 5208e4e..1dfa5a2 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -78,7 +78,7 @@ protected: Wrapped(GodotObject *p_godot_object); public: - static StringName get_class_static() { + static StringName &get_class_static() { static StringName string_name = StringName("Wrapped"); return string_name; } @@ -159,12 +159,12 @@ public: initialized = true; \ } \ \ - static StringName get_class_static() { \ + static StringName &get_class_static() { \ static StringName string_name = StringName(#m_class); \ return string_name; \ } \ \ - static StringName get_parent_class_static() { \ + static StringName &get_parent_class_static() { \ return m_inherits::get_class_static(); \ } \ \ @@ -349,12 +349,12 @@ protected: public: \ static void initialize_class() {} \ \ - static StringName get_class_static() { \ + static StringName &get_class_static() { \ static StringName string_name = StringName(#m_class); \ return string_name; \ } \ \ - static StringName get_parent_class_static() { \ + static StringName &get_parent_class_static() { \ return m_inherits::get_class_static(); \ } \ \ diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index 0353621..634e55c 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -191,7 +191,7 @@ void ClassDB::_register_class(bool p_virtual) { T::free, // GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */ &ClassDB::get_virtual_func, // GDNativeExtensionClassGetVirtual get_virtual_func; nullptr, // GDNativeExtensionClassGetRID get_rid; - (void *)&cl.name, // void *class_userdata; + (void *)&T::get_class_static(), // void *class_userdata; }; internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info); @@ -249,7 +249,7 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p std::unordered_map::iterator type_it = classes.find(instance_type); if (type_it == classes.end()) { memdelete(bind); - ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(instance_type)); + ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(Array::make(instance_type))); } ClassInfo &type = type_it->second; diff --git a/include/godot_cpp/core/method_bind.hpp b/include/godot_cpp/core/method_bind.hpp index c80c040..d7d747d 100644 --- a/include/godot_cpp/core/method_bind.hpp +++ b/include/godot_cpp/core/method_bind.hpp @@ -121,7 +121,7 @@ public: std::vector vec; // First element is return value vec.reserve(argument_count + 1); - for (int i = 0; i < argument_count; i++) { + for (int i = 0; i < argument_count + 1; i++) { vec.push_back(get_argument_info(i - 1)); } return vec; diff --git a/src/core/class_db.cpp b/src/core/class_db.cpp index 49cc9bd..97112b7 100644 --- a/src/core/class_db.cpp +++ b/src/core/class_db.cpp @@ -115,7 +115,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf } MethodBind *ClassDB::get_method(const StringName &p_class, const StringName &p_method) { - ERR_FAIL_COND_V_MSG(classes.find(p_class) == classes.end(), nullptr, String("Class '{0}' not found.").format(p_class)); + ERR_FAIL_COND_V_MSG(classes.find(p_class) == classes.end(), nullptr, String("Class '{0}' not found.").format(Array::make(p_class))); ClassInfo *type = &classes[p_class]; while (type) { @@ -136,7 +136,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const M std::unordered_map::iterator type_it = classes.find(instance_type); if (type_it == classes.end()) { memdelete(p_bind); - ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(instance_type)); + ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(Array::make(instance_type))); } ClassInfo &type = type_it->second; @@ -240,7 +240,7 @@ void ClassDB::bind_method_godot(const StringName &p_class_name, MethodBind *p_me void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal) { std::unordered_map::iterator type_it = classes.find(p_class); - ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(p_class)); + ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(Array::make(p_class))); ClassInfo &cl = type_it->second; @@ -275,7 +275,7 @@ void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal) void ClassDB::bind_integer_constant(const StringName &p_class_name, const StringName &p_enum_name, const StringName &p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield) { std::unordered_map::iterator type_it = classes.find(p_class_name); - ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(p_class_name)); + ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(Array::make(p_class_name))); ClassInfo &type = type_it->second; @@ -296,7 +296,7 @@ GDNativeExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, co const StringName *name = reinterpret_cast(p_name); std::unordered_map::iterator type_it = classes.find(*class_name); - ERR_FAIL_COND_V_MSG(type_it == classes.end(), nullptr, String("Class '{0}' doesn't exist.").format(*class_name)); + ERR_FAIL_COND_V_MSG(type_it == classes.end(), nullptr, String("Class '{0}' doesn't exist.").format(Array::make(*class_name))); const ClassInfo *type = &type_it->second; @@ -316,7 +316,7 @@ GDNativeExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, co void ClassDB::bind_virtual_method(const StringName &p_class, const StringName &p_method, GDNativeExtensionClassCallVirtual p_call) { std::unordered_map::iterator type_it = classes.find(p_class); - ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(p_class)); + ERR_FAIL_COND_MSG(type_it == classes.end(), String("Class '{0}' doesn't exist.").format(Array::make(p_class))); ClassInfo &type = type_it->second; diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp index 5a1bcb2..6494bb9 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -49,8 +49,8 @@ void Variant::init_bindings() { to_type_constructor[i] = internal::gdn_interface->get_variant_to_type_constructor((GDNativeVariantType)i); } - String::init_bindings(); StringName::init_bindings(); + String::init_bindings(); NodePath::init_bindings(); RID::init_bindings(); Callable::init_bindings();