StringName is working fine with demo \o/

pull/896/head
Emmanuel Leblond 2022-10-23 22:31:57 +02:00
parent 3b82d5937b
commit b6ba0dca13
No known key found for this signature in database
GPG Key ID: C360860E645EFFC0
6 changed files with 29 additions and 17 deletions

View File

@ -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"]:

View File

@ -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(); \
} \
\

View File

@ -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<StringName, ClassInfo>::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;

View File

@ -121,7 +121,7 @@ public:
std::vector<PropertyInfo> 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;

View File

@ -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<StringName, ClassInfo>::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<StringName, ClassInfo>::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<StringName, ClassInfo>::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<const StringName *>(p_name);
std::unordered_map<StringName, ClassInfo>::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<StringName, ClassInfo>::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;

View File

@ -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();