Use StringName in the whole GDExtension API instead of const char *
parent
0e81f89dd3
commit
e24b6b0e51
|
@ -394,9 +394,6 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
|
||||||
result.append(f"class {class_name} {{")
|
result.append(f"class {class_name} {{")
|
||||||
result.append(f"\tstatic constexpr size_t {snake_class_name}_SIZE = {size};")
|
result.append(f"\tstatic constexpr size_t {snake_class_name}_SIZE = {size};")
|
||||||
result.append(f"\tuint8_t opaque[{snake_class_name}_SIZE] = {{}};")
|
result.append(f"\tuint8_t opaque[{snake_class_name}_SIZE] = {{}};")
|
||||||
result.append(
|
|
||||||
f"\t_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const {{ return const_cast<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
|
|
||||||
)
|
|
||||||
|
|
||||||
result.append("")
|
result.append("")
|
||||||
result.append("\tfriend class Variant;")
|
result.append("\tfriend class Variant;")
|
||||||
|
@ -446,6 +443,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
|
||||||
result.append("")
|
result.append("")
|
||||||
result.append("public:")
|
result.append("public:")
|
||||||
|
|
||||||
|
result.append(
|
||||||
|
f"\t_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const {{ return const_cast<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
|
||||||
|
)
|
||||||
|
|
||||||
copy_constructor_index = -1
|
copy_constructor_index = -1
|
||||||
|
|
||||||
if "constructors" in builtin_api:
|
if "constructors" in builtin_api:
|
||||||
|
@ -694,17 +695,17 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
|
||||||
# TODO: Add error check for hash mismatch.
|
# TODO: Add error check for hash mismatch.
|
||||||
result.append(f'\t__name = StringName("{method["name"]}");')
|
result.append(f'\t__name = StringName("{method["name"]}");')
|
||||||
result.append(
|
result.append(
|
||||||
f'\t_method_bindings.method_{method["name"]} = internal::gdn_interface->variant_get_ptr_builtin_method({enum_type_name}, (void *)&__name, {method["hash"]});'
|
f'\t_method_bindings.method_{method["name"]} = internal::gdn_interface->variant_get_ptr_builtin_method({enum_type_name}, __name._native_ptr(), {method["hash"]});'
|
||||||
)
|
)
|
||||||
|
|
||||||
if "members" in builtin_api:
|
if "members" in builtin_api:
|
||||||
for member in builtin_api["members"]:
|
for member in builtin_api["members"]:
|
||||||
result.append(f'\t__name = StringName("{member["name"]}");')
|
result.append(f'\t__name = StringName("{member["name"]}");')
|
||||||
result.append(
|
result.append(
|
||||||
f'\t_method_bindings.member_{member["name"]}_setter = internal::gdn_interface->variant_get_ptr_setter({enum_type_name}, (void *)&__name);'
|
f'\t_method_bindings.member_{member["name"]}_setter = internal::gdn_interface->variant_get_ptr_setter({enum_type_name}, __name._native_ptr());'
|
||||||
)
|
)
|
||||||
result.append(
|
result.append(
|
||||||
f'\t_method_bindings.member_{member["name"]}_getter = internal::gdn_interface->variant_get_ptr_getter({enum_type_name}, (void *)&__name);'
|
f'\t_method_bindings.member_{member["name"]}_getter = internal::gdn_interface->variant_get_ptr_getter({enum_type_name}, __name._native_ptr());'
|
||||||
)
|
)
|
||||||
|
|
||||||
if "indexing_return_type" in builtin_api:
|
if "indexing_return_type" in builtin_api:
|
||||||
|
@ -1296,9 +1297,9 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
|
||||||
|
|
||||||
if is_singleton:
|
if is_singleton:
|
||||||
result.append(f"{class_name} *{class_name}::get_singleton() {{")
|
result.append(f"{class_name} *{class_name}::get_singleton() {{")
|
||||||
result.append(f'\tconst StringName __class_name = {class_name}::get_class_static();')
|
result.append(f"\tconst StringName __class_name = {class_name}::get_class_static();")
|
||||||
result.append(
|
result.append(
|
||||||
f"\tstatic GDNativeObjectPtr singleton_obj = internal::gdn_interface->global_get_singleton((void *)&__class_name);"
|
f"\tstatic GDNativeObjectPtr singleton_obj = internal::gdn_interface->global_get_singleton(__class_name._native_ptr());"
|
||||||
)
|
)
|
||||||
result.append("#ifdef DEBUG_ENABLED")
|
result.append("#ifdef DEBUG_ENABLED")
|
||||||
result.append("\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);")
|
result.append("\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);")
|
||||||
|
@ -1323,10 +1324,10 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
|
||||||
result.append(method_signature + " {")
|
result.append(method_signature + " {")
|
||||||
|
|
||||||
# Method body.
|
# Method body.
|
||||||
result.append(f'\tconst StringName __class_name = {class_name}::get_class_static();')
|
result.append(f"\tconst StringName __class_name = {class_name}::get_class_static();")
|
||||||
result.append(f'\tconst StringName __method_name = "{method["name"]}";')
|
result.append(f'\tconst StringName __method_name = "{method["name"]}";')
|
||||||
result.append(
|
result.append(
|
||||||
f'\tstatic GDNativeMethodBindPtr ___method_bind = internal::gdn_interface->classdb_get_method_bind((void *)&__class_name, (void *)&__method_name, {method["hash"]});'
|
f'\tstatic GDNativeMethodBindPtr ___method_bind = internal::gdn_interface->classdb_get_method_bind(__class_name._native_ptr(), __method_name._native_ptr(), {method["hash"]});'
|
||||||
)
|
)
|
||||||
method_call = "\t"
|
method_call = "\t"
|
||||||
has_return = "return_value" in method and method["return_value"]["type"] != "void"
|
has_return = "return_value" in method and method["return_value"]["type"] != "void"
|
||||||
|
@ -1575,7 +1576,7 @@ def generate_utility_functions(api, output_dir):
|
||||||
|
|
||||||
source.append(f'\tconst StringName __function_name = "{function["name"]}";')
|
source.append(f'\tconst StringName __function_name = "{function["name"]}";')
|
||||||
source.append(
|
source.append(
|
||||||
f'\tstatic GDNativePtrUtilityFunction ___function = internal::gdn_interface->variant_get_ptr_utility_function((void *)&__function_name, {function["hash"]});'
|
f'\tstatic GDNativePtrUtilityFunction ___function = internal::gdn_interface->variant_get_ptr_utility_function(__function_name._native_ptr(), {function["hash"]});'
|
||||||
)
|
)
|
||||||
has_return = "return_type" in function and function["return_type"] != "void"
|
has_return = "return_type" in function and function["return_type"] != "void"
|
||||||
if has_return:
|
if has_return:
|
||||||
|
|
|
@ -202,21 +202,21 @@ typedef uint64_t (*GDNativeExtensionClassGetRID)(GDExtensionClassInstancePtr p_i
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GDNativeVariantType type;
|
GDNativeVariantType type;
|
||||||
const char *name;
|
GDNativeStringNamePtr name;
|
||||||
const char *class_name;
|
GDNativeStringNamePtr class_name;
|
||||||
uint32_t hint; // Bitfield of `PropertyHint` (defined in `extension_api.json`)
|
uint32_t hint; // Bitfield of `PropertyHint` (defined in `extension_api.json`)
|
||||||
const char *hint_string;
|
GDNativeStringPtr hint_string;
|
||||||
uint32_t usage; // Bitfield of `PropertyUsageFlags` (defined in `extension_api.json`)
|
uint32_t usage; // Bitfield of `PropertyUsageFlags` (defined in `extension_api.json`)
|
||||||
} GDNativePropertyInfo;
|
} GDNativePropertyInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
GDNativeStringNamePtr name;
|
||||||
GDNativePropertyInfo return_value;
|
GDNativePropertyInfo return_value;
|
||||||
uint32_t flags; // Bitfield of `GDNativeExtensionClassMethodFlags`
|
uint32_t flags; // Bitfield of `GDNativeExtensionClassMethodFlags`
|
||||||
int32_t id;
|
int32_t id;
|
||||||
GDNativePropertyInfo *arguments;
|
GDNativePropertyInfo *arguments; // array of `argument_count` size
|
||||||
uint32_t argument_count;
|
uint32_t argument_count;
|
||||||
GDNativeVariantPtr default_arguments;
|
GDNativeVariantPtr *default_arguments; // array of `default_argument_count` size
|
||||||
uint32_t default_argument_count;
|
uint32_t default_argument_count;
|
||||||
} GDNativeMethodInfo;
|
} GDNativeMethodInfo;
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ typedef void (*GDNativeExtensionClassUnreference)(GDExtensionClassInstancePtr p_
|
||||||
typedef void (*GDNativeExtensionClassCallVirtual)(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret);
|
typedef void (*GDNativeExtensionClassCallVirtual)(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret);
|
||||||
typedef GDNativeObjectPtr (*GDNativeExtensionClassCreateInstance)(void *p_userdata);
|
typedef GDNativeObjectPtr (*GDNativeExtensionClassCreateInstance)(void *p_userdata);
|
||||||
typedef void (*GDNativeExtensionClassFreeInstance)(void *p_userdata, GDExtensionClassInstancePtr p_instance);
|
typedef void (*GDNativeExtensionClassFreeInstance)(void *p_userdata, GDExtensionClassInstancePtr p_instance);
|
||||||
typedef GDNativeExtensionClassCallVirtual (*GDNativeExtensionClassGetVirtual)(void *p_userdata, const char *p_name);
|
typedef GDNativeExtensionClassCallVirtual (*GDNativeExtensionClassGetVirtual)(void *p_userdata, const GDNativeStringNamePtr p_name);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GDNativeBool is_virtual;
|
GDNativeBool is_virtual;
|
||||||
|
@ -284,24 +284,21 @@ typedef enum {
|
||||||
typedef void (*GDNativeExtensionClassMethodCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error);
|
typedef void (*GDNativeExtensionClassMethodCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error);
|
||||||
typedef void (*GDNativeExtensionClassMethodPtrCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret);
|
typedef void (*GDNativeExtensionClassMethodPtrCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret);
|
||||||
|
|
||||||
/* passing -1 as argument in the following functions refers to the return type */
|
|
||||||
typedef GDNativeVariantType (*GDNativeExtensionClassMethodGetArgumentType)(void *p_method_userdata, int32_t p_argument);
|
|
||||||
typedef void (*GDNativeExtensionClassMethodGetArgumentInfo)(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info);
|
|
||||||
typedef GDNativeExtensionClassMethodArgumentMetadata (*GDNativeExtensionClassMethodGetArgumentMetadata)(void *p_method_userdata, int32_t p_argument);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
GDNativeStringNamePtr name;
|
||||||
void *method_userdata;
|
void *method_userdata;
|
||||||
GDNativeExtensionClassMethodCall call_func;
|
GDNativeExtensionClassMethodCall call_func;
|
||||||
GDNativeExtensionClassMethodPtrCall ptrcall_func;
|
GDNativeExtensionClassMethodPtrCall ptrcall_func;
|
||||||
uint32_t method_flags; // Bitfield of `GDNativeExtensionClassMethodFlags`
|
uint32_t method_flags; // Bitfield of `GDNativeExtensionClassMethodFlags`
|
||||||
uint32_t argument_count;
|
uint32_t argument_count;
|
||||||
GDNativeBool has_return_value;
|
GDNativeBool has_return_value;
|
||||||
GDNativeExtensionClassMethodGetArgumentType get_argument_type_func;
|
GDNativePropertyInfo *return_value_info; // Ignored if `has_return_value` is false
|
||||||
GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; /* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */
|
GDNativeExtensionClassMethodArgumentMetadata return_value_metadata; // Ignored if `has_return_value` is false
|
||||||
GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func;
|
/* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */
|
||||||
|
GDNativePropertyInfo *aguments_info; // array of `argument_count` size
|
||||||
|
GDNativeExtensionClassMethodArgumentMetadata *aguments_metadata; // array of `argument_count` size
|
||||||
uint32_t default_argument_count;
|
uint32_t default_argument_count;
|
||||||
GDNativeVariantPtr *default_arguments;
|
GDNativeVariantPtr *default_arguments; // array of `default_argument_count` size
|
||||||
} GDNativeExtensionClassMethodInfo;
|
} GDNativeExtensionClassMethodInfo;
|
||||||
|
|
||||||
/* SCRIPT INSTANCE EXTENSION */
|
/* SCRIPT INSTANCE EXTENSION */
|
||||||
|
@ -312,7 +309,6 @@ typedef GDNativeBool (*GDNativeExtensionScriptInstanceSet)(GDNativeExtensionScri
|
||||||
typedef GDNativeBool (*GDNativeExtensionScriptInstanceGet)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
|
typedef GDNativeBool (*GDNativeExtensionScriptInstanceGet)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
|
||||||
typedef const GDNativePropertyInfo *(*GDNativeExtensionScriptInstanceGetPropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
|
typedef const GDNativePropertyInfo *(*GDNativeExtensionScriptInstanceGetPropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
|
||||||
typedef void (*GDNativeExtensionScriptInstanceFreePropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativePropertyInfo *p_list);
|
typedef void (*GDNativeExtensionScriptInstanceFreePropertyList)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativePropertyInfo *p_list);
|
||||||
typedef GDNativeVariantType (*GDNativeExtensionScriptInstanceGetPropertyType)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeBool *r_is_valid);
|
|
||||||
|
|
||||||
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyCanRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name);
|
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyCanRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name);
|
||||||
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyGetRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
|
typedef GDNativeBool (*GDNativeExtensionScriptInstancePropertyGetRevert)(GDNativeExtensionScriptInstanceDataPtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret);
|
||||||
|
@ -349,7 +345,6 @@ typedef struct {
|
||||||
GDNativeExtensionScriptInstanceGet get_func;
|
GDNativeExtensionScriptInstanceGet get_func;
|
||||||
GDNativeExtensionScriptInstanceGetPropertyList get_property_list_func;
|
GDNativeExtensionScriptInstanceGetPropertyList get_property_list_func;
|
||||||
GDNativeExtensionScriptInstanceFreePropertyList free_property_list_func;
|
GDNativeExtensionScriptInstanceFreePropertyList free_property_list_func;
|
||||||
GDNativeExtensionScriptInstanceGetPropertyType get_property_type_func;
|
|
||||||
|
|
||||||
GDNativeExtensionScriptInstancePropertyCanRevert property_can_revert_func;
|
GDNativeExtensionScriptInstancePropertyCanRevert property_can_revert_func;
|
||||||
GDNativeExtensionScriptInstancePropertyGetRevert property_get_revert_func;
|
GDNativeExtensionScriptInstancePropertyGetRevert property_get_revert_func;
|
||||||
|
@ -546,14 +541,15 @@ typedef struct {
|
||||||
|
|
||||||
/* CLASSDB EXTENSION */
|
/* CLASSDB EXTENSION */
|
||||||
|
|
||||||
void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs);
|
// Provided parameters for `classdb_register_extension_*` can be safely freed once the function returns
|
||||||
void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info);
|
void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs);
|
||||||
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield);
|
void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info);
|
||||||
void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter);
|
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_enum_name, const GDNativeStringNamePtr p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield);
|
||||||
void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix);
|
void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativePropertyInfo *p_info, const GDNativeStringNamePtr p_setter, const GDNativeStringNamePtr p_getter);
|
||||||
void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix);
|
void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_group_name, const GDNativeStringPtr p_prefix);
|
||||||
void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count);
|
void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_subgroup_name, const GDNativeStringPtr p_prefix);
|
||||||
void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */
|
void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count);
|
||||||
|
void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */
|
||||||
|
|
||||||
void (*get_library_path)(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path);
|
void (*get_library_path)(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path);
|
||||||
|
|
||||||
|
|
|
@ -264,8 +264,8 @@ struct GetTypeInfo<Ref<T>, typename EnableIf<TypeInherits<RefCounted, T>::value>
|
||||||
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
|
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
|
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -274,8 +274,8 @@ struct GetTypeInfo<const Ref<T> &, typename EnableIf<TypeInherits<RefCounted, T>
|
||||||
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
|
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
|
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Wrapped {
|
||||||
friend void postinitialize_handler(Wrapped *);
|
friend void postinitialize_handler(Wrapped *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const StringName *_get_extension_class() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
|
virtual const StringName *_get_extension_class_name() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
|
||||||
virtual const GDNativeInstanceBindingCallbacks *_get_bindings_callbacks() const = 0;
|
virtual const GDNativeInstanceBindingCallbacks *_get_bindings_callbacks() const = 0;
|
||||||
|
|
||||||
void _notification(int p_what){};
|
void _notification(int p_what){};
|
||||||
|
@ -106,7 +106,7 @@ private:
|
||||||
friend class ::godot::ClassDB; \
|
friend class ::godot::ClassDB; \
|
||||||
\
|
\
|
||||||
protected: \
|
protected: \
|
||||||
virtual const StringName *_get_extension_class() const override { \
|
virtual const StringName *_get_extension_class_name() const override { \
|
||||||
static StringName string_name = get_class_static(); \
|
static StringName string_name = get_class_static(); \
|
||||||
return &string_name; \
|
return &string_name; \
|
||||||
} \
|
} \
|
||||||
|
@ -171,7 +171,7 @@ public:
|
||||||
return string_name; \
|
return string_name; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static StringName *get_parent_class_static() { \
|
static StringName get_parent_class_static() { \
|
||||||
return m_inherits::get_class_static(); \
|
return m_inherits::get_class_static(); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -223,10 +223,10 @@ public:
|
||||||
cls->plist_size = 0; \
|
cls->plist_size = 0; \
|
||||||
for (const ::godot::PropertyInfo &E : list) { \
|
for (const ::godot::PropertyInfo &E : list) { \
|
||||||
cls->plist[cls->plist_size].type = static_cast<GDNativeVariantType>(E.type); \
|
cls->plist[cls->plist_size].type = static_cast<GDNativeVariantType>(E.type); \
|
||||||
cls->plist[cls->plist_size].name = _alloc_and_copy_cstr(E.name.utf8().get_data()); \
|
cls->plist[cls->plist_size].name = E.name._native_ptr(); \
|
||||||
cls->plist[cls->plist_size].hint = E.hint; \
|
cls->plist[cls->plist_size].hint = E.hint; \
|
||||||
cls->plist[cls->plist_size].hint_string = _alloc_and_copy_cstr(E.hint_string.utf8().get_data()); \
|
cls->plist[cls->plist_size].hint_string = E.hint_string._native_ptr(); \
|
||||||
cls->plist[cls->plist_size].class_name = _alloc_and_copy_cstr(E.class_name.utf8().get_data()); \
|
cls->plist[cls->plist_size].class_name = E.class_name._native_ptr(); \
|
||||||
cls->plist[cls->plist_size].usage = E.usage; \
|
cls->plist[cls->plist_size].usage = E.usage; \
|
||||||
cls->plist_size++; \
|
cls->plist_size++; \
|
||||||
} \
|
} \
|
||||||
|
@ -243,11 +243,6 @@ public:
|
||||||
if (p_instance) { \
|
if (p_instance) { \
|
||||||
m_class *cls = reinterpret_cast<m_class *>(p_instance); \
|
m_class *cls = reinterpret_cast<m_class *>(p_instance); \
|
||||||
ERR_FAIL_COND_MSG(cls->plist == nullptr, "Internal error, property list double free!"); \
|
ERR_FAIL_COND_MSG(cls->plist == nullptr, "Internal error, property list double free!"); \
|
||||||
for (size_t i = 0; i < cls->plist_size; i++) { \
|
|
||||||
memfree(const_cast<char *>(cls->plist[i].name)); \
|
|
||||||
memfree(const_cast<char *>(cls->plist[i].class_name)); \
|
|
||||||
memfree(const_cast<char *>(cls->plist[i].hint_string)); \
|
|
||||||
} \
|
|
||||||
memfree(cls->plist); \
|
memfree(cls->plist); \
|
||||||
cls->plist = nullptr; \
|
cls->plist = nullptr; \
|
||||||
cls->plist_size = 0; \
|
cls->plist_size = 0; \
|
||||||
|
|
|
@ -423,7 +423,7 @@ GDNativeVariantType call_get_argument_type(int p_arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Q>
|
template <class Q>
|
||||||
void call_get_argument_type_info_helper(int p_arg, int &index, GDNativePropertyInfo &info) {
|
void call_get_argument_type_info_helper(int p_arg, int &index, PropertyInfo &info) {
|
||||||
if (p_arg == index) {
|
if (p_arg == index) {
|
||||||
info = GetTypeInfo<Q>::get_class_info();
|
info = GetTypeInfo<Q>::get_class_info();
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ void call_get_argument_type_info_helper(int p_arg, int &index, GDNativePropertyI
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... P>
|
template <class... P>
|
||||||
void call_get_argument_type_info(int p_arg, GDNativePropertyInfo &info) {
|
void call_get_argument_type_info(int p_arg, PropertyInfo &info) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
// I think rocket science is simpler than modern C++.
|
// I think rocket science is simpler than modern C++.
|
||||||
using expand_type = int[];
|
using expand_type = int[];
|
||||||
|
|
|
@ -44,22 +44,30 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
// Needed to use StringName as key in `std::unordered_map`
|
||||||
|
template <>
|
||||||
|
struct std::hash<godot::StringName> {
|
||||||
|
std::size_t operator()(godot::StringName const &s) const noexcept {
|
||||||
|
return s.hash();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
#define DEFVAL(m_defval) (m_defval)
|
#define DEFVAL(m_defval) (m_defval)
|
||||||
|
|
||||||
struct MethodDefinition {
|
struct MethodDefinition {
|
||||||
const char *name = nullptr;
|
StringName name;
|
||||||
std::list<std::string> args;
|
std::list<StringName> args;
|
||||||
MethodDefinition() {}
|
MethodDefinition() {}
|
||||||
MethodDefinition(const char *p_name) :
|
MethodDefinition(StringName p_name) :
|
||||||
name(p_name) {}
|
name(p_name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
MethodDefinition D_METHOD(const char *p_name);
|
MethodDefinition D_METHOD(StringName p_name);
|
||||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1);
|
MethodDefinition D_METHOD(StringName p_name, StringName p_arg1);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, Args... args) {
|
MethodDefinition D_METHOD(StringName p_name, StringName p_arg1, Args... args) {
|
||||||
MethodDefinition md = D_METHOD(p_name, args...);
|
MethodDefinition md = D_METHOD(p_name, args...);
|
||||||
md.args.push_front(p_arg1);
|
md.args.push_front(p_arg1);
|
||||||
return md;
|
return md;
|
||||||
|
@ -73,33 +81,33 @@ class ClassDB {
|
||||||
public:
|
public:
|
||||||
struct PropertySetGet {
|
struct PropertySetGet {
|
||||||
int index;
|
int index;
|
||||||
const char *setter;
|
StringName setter;
|
||||||
const char *getter;
|
StringName getter;
|
||||||
MethodBind *_setptr;
|
MethodBind *_setptr;
|
||||||
MethodBind *_getptr;
|
MethodBind *_getptr;
|
||||||
Variant::Type type;
|
Variant::Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ClassInfo {
|
struct ClassInfo {
|
||||||
const char *name = nullptr;
|
StringName name;
|
||||||
const char *parent_name = nullptr;
|
StringName parent_name;
|
||||||
GDNativeInitializationLevel level = GDNATIVE_INITIALIZATION_SCENE;
|
GDNativeInitializationLevel level = GDNATIVE_INITIALIZATION_SCENE;
|
||||||
std::unordered_map<std::string, MethodBind *> method_map;
|
std::unordered_map<StringName, MethodBind *> method_map;
|
||||||
std::set<std::string> signal_names;
|
std::set<StringName> signal_names;
|
||||||
std::unordered_map<std::string, GDNativeExtensionClassCallVirtual> virtual_methods;
|
std::unordered_map<StringName, GDNativeExtensionClassCallVirtual> virtual_methods;
|
||||||
std::set<std::string> property_names;
|
std::set<StringName> property_names;
|
||||||
std::set<std::string> constant_names;
|
std::set<StringName> constant_names;
|
||||||
// Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class.
|
// Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class.
|
||||||
ClassInfo *parent_ptr = nullptr;
|
ClassInfo *parent_ptr = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This may only contain custom classes, not Godot classes
|
// This may only contain custom classes, not Godot classes
|
||||||
static std::unordered_map<std::string, ClassInfo> classes;
|
static std::unordered_map<StringName, ClassInfo> classes;
|
||||||
|
|
||||||
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
|
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
|
||||||
static void initialize_class(const ClassInfo &cl);
|
static void initialize_class(const ClassInfo &cl);
|
||||||
static void bind_method_godot(const char *p_class_name, MethodBind *p_method);
|
static void bind_method_godot(const StringName &p_class_name, MethodBind *p_method);
|
||||||
|
|
||||||
static _FORCE_INLINE_ char *_alloc_and_copy_cstr(const char *p_str) {
|
static _FORCE_INLINE_ char *_alloc_and_copy_cstr(const char *p_str) {
|
||||||
size_t size = strlen(p_str) + 1;
|
size_t size = strlen(p_str) + 1;
|
||||||
|
@ -121,21 +129,21 @@ public:
|
||||||
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args);
|
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args);
|
||||||
|
|
||||||
template <class N, class M, typename... VarArgs>
|
template <class N, class M, typename... VarArgs>
|
||||||
static MethodBind *bind_static_method(const char *p_class, N p_method_name, M p_method, VarArgs... p_args);
|
static MethodBind *bind_static_method(StringName p_class, N p_method_name, M p_method, VarArgs... p_args);
|
||||||
|
|
||||||
template <class M>
|
template <class M>
|
||||||
static MethodBind *bind_vararg_method(uint32_t p_flags, const char *p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const std::vector<Variant> &p_default_args = std::vector<Variant>{}, bool p_return_nil_is_variant = true);
|
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const std::vector<Variant> &p_default_args = std::vector<Variant>{}, bool p_return_nil_is_variant = true);
|
||||||
|
|
||||||
static void add_property_group(const char *p_class, const char *p_name, const char *p_prefix);
|
static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix);
|
||||||
static void add_property_subgroup(const char *p_class, const char *p_name, const char *p_prefix);
|
static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix);
|
||||||
static void add_property(const char *p_class, const PropertyInfo &p_pinfo, const char *p_setter, const char *p_getter, int p_index = -1);
|
static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
|
||||||
static void add_signal(const char *p_class, const MethodInfo &p_signal);
|
static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
|
||||||
static void bind_integer_constant(const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield = false);
|
static void 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 = false);
|
||||||
static void bind_virtual_method(const char *p_class, const char *p_method, GDNativeExtensionClassCallVirtual p_call);
|
static void bind_virtual_method(const StringName &p_class, const StringName &p_method, GDNativeExtensionClassCallVirtual p_call);
|
||||||
|
|
||||||
static MethodBind *get_method(const char *p_class, const char *p_method);
|
static MethodBind *get_method(const StringName &p_class, const StringName &p_method);
|
||||||
|
|
||||||
static GDNativeExtensionClassCallVirtual get_virtual_func(void *p_userdata, const char *p_name);
|
static GDNativeExtensionClassCallVirtual get_virtual_func(void *p_userdata, const GDNativeStringNamePtr p_name);
|
||||||
|
|
||||||
static void initialize(GDNativeInitializationLevel p_level);
|
static void initialize(GDNativeInitializationLevel p_level);
|
||||||
static void deinitialize(GDNativeInitializationLevel p_level);
|
static void deinitialize(GDNativeInitializationLevel p_level);
|
||||||
|
@ -165,7 +173,7 @@ void ClassDB::_register_class(bool p_virtual) {
|
||||||
cl.name = T::get_class_static();
|
cl.name = T::get_class_static();
|
||||||
cl.parent_name = T::get_parent_class_static();
|
cl.parent_name = T::get_parent_class_static();
|
||||||
cl.level = current_level;
|
cl.level = current_level;
|
||||||
std::unordered_map<std::string, ClassInfo>::iterator parent_it = classes.find(cl.parent_name);
|
std::unordered_map<StringName, ClassInfo>::iterator parent_it = classes.find(cl.parent_name);
|
||||||
if (parent_it != classes.end()) {
|
if (parent_it != classes.end()) {
|
||||||
// Assign parent if it is also a custom class
|
// Assign parent if it is also a custom class
|
||||||
cl.parent_ptr = &parent_it->second;
|
cl.parent_ptr = &parent_it->second;
|
||||||
|
@ -190,10 +198,10 @@ void ClassDB::_register_class(bool p_virtual) {
|
||||||
T::free, // GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
|
T::free, // GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
|
||||||
&ClassDB::get_virtual_func, // GDNativeExtensionClassGetVirtual get_virtual_func;
|
&ClassDB::get_virtual_func, // GDNativeExtensionClassGetVirtual get_virtual_func;
|
||||||
nullptr, // GDNativeExtensionClassGetRID get_rid;
|
nullptr, // GDNativeExtensionClassGetRID get_rid;
|
||||||
(void *)cl.name, // void *class_userdata;
|
(void *)&cl.name, // void *class_userdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name, cl.parent_name, &class_info);
|
internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info);
|
||||||
|
|
||||||
// call bind_methods etc. to register all members of the class
|
// call bind_methods etc. to register all members of the class
|
||||||
T::initialize_class();
|
T::initialize_class();
|
||||||
|
@ -224,7 +232,7 @@ MethodBind *ClassDB::bind_method(N p_method_name, M p_method, VarArgs... p_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class N, class M, typename... VarArgs>
|
template <class N, class M, typename... VarArgs>
|
||||||
MethodBind *ClassDB::bind_static_method(const char *p_class, N p_method_name, M p_method, VarArgs... p_args) {
|
MethodBind *ClassDB::bind_static_method(StringName p_class, N p_method_name, M p_method, VarArgs... p_args) {
|
||||||
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
||||||
const Variant *argptrs[sizeof...(p_args) + 1];
|
const Variant *argptrs[sizeof...(p_args) + 1];
|
||||||
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
||||||
|
@ -236,16 +244,16 @@ MethodBind *ClassDB::bind_static_method(const char *p_class, N p_method_name, M
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class M>
|
template <class M>
|
||||||
MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, const char *p_name, M p_method, const MethodInfo &p_info, const std::vector<Variant> &p_default_args, bool p_return_nil_is_variant) {
|
MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info, const std::vector<Variant> &p_default_args, bool p_return_nil_is_variant) {
|
||||||
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
|
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
|
||||||
ERR_FAIL_COND_V(!bind, nullptr);
|
ERR_FAIL_COND_V(!bind, nullptr);
|
||||||
|
|
||||||
bind->set_name(p_name);
|
bind->set_name(p_name);
|
||||||
bind->set_default_arguments(p_default_args);
|
bind->set_default_arguments(p_default_args);
|
||||||
|
|
||||||
const char *instance_type = bind->get_instance_class();
|
StringName instance_type = bind->get_instance_class();
|
||||||
|
|
||||||
std::unordered_map<std::string, ClassInfo>::iterator type_it = classes.find(instance_type);
|
std::unordered_map<StringName, ClassInfo>::iterator type_it = classes.find(instance_type);
|
||||||
if (type_it == classes.end()) {
|
if (type_it == classes.end()) {
|
||||||
memdelete(bind);
|
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(instance_type));
|
||||||
|
|
|
@ -48,8 +48,8 @@
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
class MethodBind {
|
class MethodBind {
|
||||||
const char *name = nullptr;
|
StringName name;
|
||||||
const char *instance_class = nullptr;
|
StringName instance_class;
|
||||||
int argument_count = 0;
|
int argument_count = 0;
|
||||||
uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
|
uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ class MethodBind {
|
||||||
bool _has_return = false;
|
bool _has_return = false;
|
||||||
bool _vararg = false;
|
bool _vararg = false;
|
||||||
|
|
||||||
std::vector<std::string> argument_names;
|
std::vector<StringName> argument_names;
|
||||||
GDNativeVariantType *argument_types = nullptr;
|
GDNativeVariantType *argument_types = nullptr;
|
||||||
std::vector<Variant> default_arguments;
|
std::vector<Variant> default_arguments;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual GDNativeVariantType gen_argument_type(int p_arg) const = 0;
|
virtual GDNativeVariantType gen_argument_type(int p_arg) const = 0;
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const = 0;
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const = 0;
|
||||||
void generate_argument_types(int p_count);
|
void generate_argument_types(int p_count);
|
||||||
void set_const(bool p_const);
|
void set_const(bool p_const);
|
||||||
void set_return(bool p_return);
|
void set_return(bool p_return);
|
||||||
|
@ -73,8 +73,8 @@ protected:
|
||||||
void set_argument_count(int p_count);
|
void set_argument_count(int p_count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const char *get_name() const;
|
StringName get_name() const;
|
||||||
void set_name(const char *p_name);
|
void set_name(const StringName &p_name);
|
||||||
_FORCE_INLINE_ int get_default_argument_count() const { return (int)default_arguments.size(); }
|
_FORCE_INLINE_ int get_default_argument_count() const { return (int)default_arguments.size(); }
|
||||||
_FORCE_INLINE_ const std::vector<Variant> &get_default_arguments() const { return default_arguments; }
|
_FORCE_INLINE_ const std::vector<Variant> &get_default_arguments() const { return default_arguments; }
|
||||||
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
|
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
|
||||||
|
@ -95,8 +95,8 @@ public:
|
||||||
return default_arguments[idx];
|
return default_arguments[idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_FORCE_INLINE_ const char *get_instance_class() const { return instance_class; }
|
_FORCE_INLINE_ StringName get_instance_class() const { return instance_class; }
|
||||||
_FORCE_INLINE_ void set_instance_class(const char *p_class) { instance_class = p_class; }
|
_FORCE_INLINE_ void set_instance_class(StringName p_class) { instance_class = p_class; }
|
||||||
|
|
||||||
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
|
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
|
||||||
_FORCE_INLINE_ bool is_const() const { return _is_const; }
|
_FORCE_INLINE_ bool is_const() const { return _is_const; }
|
||||||
|
@ -105,8 +105,8 @@ public:
|
||||||
_FORCE_INLINE_ bool has_return() const { return _has_return; }
|
_FORCE_INLINE_ bool has_return() const { return _has_return; }
|
||||||
_FORCE_INLINE_ uint32_t get_hint_flags() const { return hint_flags | (is_const() ? GDNATIVE_EXTENSION_METHOD_FLAG_CONST : 0) | (is_vararg() ? GDNATIVE_EXTENSION_METHOD_FLAG_VARARG : 0) | (is_static() ? GDNATIVE_EXTENSION_METHOD_FLAG_STATIC : 0); }
|
_FORCE_INLINE_ uint32_t get_hint_flags() const { return hint_flags | (is_const() ? GDNATIVE_EXTENSION_METHOD_FLAG_CONST : 0) | (is_vararg() ? GDNATIVE_EXTENSION_METHOD_FLAG_VARARG : 0) | (is_static() ? GDNATIVE_EXTENSION_METHOD_FLAG_STATIC : 0); }
|
||||||
_FORCE_INLINE_ void set_hint_flags(uint32_t p_hint_flags) { hint_flags = p_hint_flags; }
|
_FORCE_INLINE_ void set_hint_flags(uint32_t p_hint_flags) { hint_flags = p_hint_flags; }
|
||||||
void set_argument_names(const std::vector<std::string> &p_names);
|
void set_argument_names(const std::vector<StringName> &p_names);
|
||||||
std::vector<std::string> get_argument_names() const;
|
std::vector<StringName> get_argument_names() const;
|
||||||
void set_default_arguments(const std::vector<Variant> &p_default_arguments) { default_arguments = p_default_arguments; }
|
void set_default_arguments(const std::vector<Variant> &p_default_arguments) { default_arguments = p_default_arguments; }
|
||||||
|
|
||||||
_FORCE_INLINE_ GDNativeVariantType get_argument_type(int p_argument) const {
|
_FORCE_INLINE_ GDNativeVariantType get_argument_type(int p_argument) const {
|
||||||
|
@ -114,17 +114,31 @@ public:
|
||||||
return argument_types[p_argument + 1];
|
return argument_types[p_argument + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
GDNativePropertyInfo get_argument_info(int p_argument) const;
|
PropertyInfo get_argument_info(int p_argument) const;
|
||||||
virtual GDNativeExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const = 0;
|
virtual GDNativeExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const = 0;
|
||||||
|
|
||||||
|
std::vector<PropertyInfo> get_arguments_info_list() const {
|
||||||
|
std::vector<PropertyInfo> vec;
|
||||||
|
// First element is return value
|
||||||
|
vec.reserve(argument_count + 1);
|
||||||
|
for (int i = 0; i < argument_count; i++) {
|
||||||
|
vec.push_back(get_argument_info(i - 1));
|
||||||
|
}
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
std::vector<GDNativeExtensionClassMethodArgumentMetadata> get_arguments_metadata_list() const {
|
||||||
|
std::vector<GDNativeExtensionClassMethodArgumentMetadata> vec;
|
||||||
|
// First element is return value
|
||||||
|
vec.reserve(argument_count + 1);
|
||||||
|
for (int i = 0; i < argument_count; i++) {
|
||||||
|
vec.push_back(get_argument_metadata(i - 1));
|
||||||
|
}
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const = 0;
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const = 0;
|
||||||
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return) const = 0;
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return) const = 0;
|
||||||
|
|
||||||
// Extension info.
|
|
||||||
static GDNativeVariantType bind_get_argument_type(void *p_method_userdata, int32_t p_argument);
|
|
||||||
static void bind_get_argument_info(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info);
|
|
||||||
static GDNativeExtensionClassMethodArgumentMetadata bind_get_argument_metadata(void *p_method_userdata, int32_t p_argument);
|
|
||||||
|
|
||||||
static void bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error);
|
static void bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error);
|
||||||
static void bind_ptrcall(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return);
|
static void bind_ptrcall(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return);
|
||||||
|
|
||||||
|
@ -136,16 +150,16 @@ class MethodBindVarArgBase : public MethodBind {
|
||||||
protected:
|
protected:
|
||||||
R(T::*method)
|
R(T::*method)
|
||||||
(const Variant **, GDNativeInt, GDNativeCallError &);
|
(const Variant **, GDNativeInt, GDNativeCallError &);
|
||||||
std::vector<GDNativePropertyInfo> arguments;
|
std::vector<PropertyInfo> arguments;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
if (p_arg < 0) {
|
if (p_arg < 0) {
|
||||||
return _gen_return_type_info();
|
return _gen_return_type_info();
|
||||||
} else if (p_arg < arguments.size()) {
|
} else if (p_arg < arguments.size()) {
|
||||||
return arguments[p_arg];
|
return arguments[p_arg];
|
||||||
} else {
|
} else {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
return make_property_info(Variant::Type::NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,20 +191,13 @@ public:
|
||||||
set_const(true);
|
set_const(true);
|
||||||
set_argument_count(p_method_info.arguments.size());
|
set_argument_count(p_method_info.arguments.size());
|
||||||
if (p_method_info.arguments.size()) {
|
if (p_method_info.arguments.size()) {
|
||||||
std::vector<std::string> names;
|
arguments = p_method_info.arguments;
|
||||||
|
|
||||||
|
std::vector<StringName> names;
|
||||||
names.reserve(p_method_info.arguments.size());
|
names.reserve(p_method_info.arguments.size());
|
||||||
for (int i = 0; i < p_method_info.arguments.size(); i++) {
|
for (int i = 0; i < p_method_info.arguments.size(); i++) {
|
||||||
names.push_back(p_method_info.arguments[i].name.utf8().get_data());
|
names.push_back(p_method_info.arguments[i].name);
|
||||||
arguments.push_back(GDNativePropertyInfo{
|
|
||||||
static_cast<GDNativeVariantType>(p_method_info.arguments[i].type), // GDNativeVariantType type;
|
|
||||||
_alloc_and_copy_cstr(p_method_info.arguments[i].name.utf8().get_data()), // const char *name;
|
|
||||||
_alloc_and_copy_cstr(p_method_info.arguments[i].class_name.utf8().get_data()), // const char *class_name;
|
|
||||||
p_method_info.arguments[i].hint, // NONE //uint32_t hint;
|
|
||||||
_alloc_and_copy_cstr(p_method_info.arguments[i].hint_string.utf8().get_data()), // const char *hint_string;
|
|
||||||
p_method_info.arguments[i].usage, // DEFAULT //uint32_t usage;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_argument_names(names);
|
set_argument_names(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,16 +205,10 @@ public:
|
||||||
set_return(should_returns);
|
set_return(should_returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MethodBindVarArgBase() {
|
~MethodBindVarArgBase() {}
|
||||||
for (GDNativePropertyInfo &arg : arguments) {
|
|
||||||
memfree(const_cast<char *>(arg.name));
|
|
||||||
memfree(const_cast<char *>(arg.class_name));
|
|
||||||
memfree(const_cast<char *>(arg.hint_string));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GDNativePropertyInfo _gen_return_type_info() const {
|
PropertyInfo _gen_return_type_info() const {
|
||||||
return reinterpret_cast<const Derived *>(this)->_gen_return_type_info_impl();
|
return reinterpret_cast<const Derived *>(this)->_gen_return_type_info_impl();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -230,7 +231,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GDNativePropertyInfo _gen_return_type_info_impl() const {
|
PropertyInfo _gen_return_type_info_impl() const {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -259,7 +260,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GDNativePropertyInfo _gen_return_type_info_impl() const {
|
PropertyInfo _gen_return_type_info_impl() const {
|
||||||
return GetTypeInfo<R>::get_class_info();
|
return GetTypeInfo<R>::get_class_info();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -302,12 +303,12 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
} else {
|
} else {
|
||||||
pi = GDNativePropertyInfo();
|
pi = PropertyInfo();
|
||||||
}
|
}
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
@ -378,12 +379,12 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
} else {
|
} else {
|
||||||
pi = GDNativePropertyInfo();
|
pi = PropertyInfo();
|
||||||
}
|
}
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
@ -455,9 +456,9 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
return pi;
|
return pi;
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,9 +539,9 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
return pi;
|
return pi;
|
||||||
} else {
|
} else {
|
||||||
|
@ -618,12 +619,12 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
} else {
|
} else {
|
||||||
pi = GDNativePropertyInfo();
|
pi = PropertyInfo();
|
||||||
}
|
}
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
@ -683,9 +684,9 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
||||||
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
||||||
GDNativePropertyInfo pi;
|
PropertyInfo pi;
|
||||||
call_get_argument_type_info<P...>(p_arg, pi);
|
call_get_argument_type_info<P...>(p_arg, pi);
|
||||||
return pi;
|
return pi;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
struct MethodInfo {
|
struct MethodInfo {
|
||||||
const char *name;
|
StringName name;
|
||||||
PropertyInfo return_val;
|
PropertyInfo return_val;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
@ -68,33 +68,33 @@ struct MethodInfo {
|
||||||
static MethodInfo from_dict(const Dictionary &p_dict);
|
static MethodInfo from_dict(const Dictionary &p_dict);
|
||||||
|
|
||||||
MethodInfo();
|
MethodInfo();
|
||||||
MethodInfo(const char *p_name);
|
MethodInfo(StringName p_name);
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo(const char *p_name, const Args &...args);
|
MethodInfo(StringName p_name, const Args &...args);
|
||||||
MethodInfo(Variant::Type ret);
|
MethodInfo(Variant::Type ret);
|
||||||
MethodInfo(Variant::Type ret, const char *p_name);
|
MethodInfo(Variant::Type ret, StringName p_name);
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo(Variant::Type ret, const char *p_name, const Args &...args);
|
MethodInfo(Variant::Type ret, StringName p_name, const Args &...args);
|
||||||
MethodInfo(const PropertyInfo &p_ret, const char *p_name);
|
MethodInfo(const PropertyInfo &p_ret, StringName p_name);
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo(const PropertyInfo &p_ret, const char *p_name, const Args &...);
|
MethodInfo(const PropertyInfo &p_ret, StringName p_name, const Args &...);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo::MethodInfo(const char *p_name, const Args &...args) :
|
MethodInfo::MethodInfo(StringName p_name, const Args &...args) :
|
||||||
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
||||||
arguments = { args... };
|
arguments = { args... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo::MethodInfo(Variant::Type ret, const char *p_name, const Args &...args) :
|
MethodInfo::MethodInfo(Variant::Type ret, StringName p_name, const Args &...args) :
|
||||||
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
||||||
return_val.type = ret;
|
return_val.type = ret;
|
||||||
arguments = { args... };
|
arguments = { args... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
MethodInfo::MethodInfo(const PropertyInfo &p_ret, const char *p_name, const Args &...args) :
|
MethodInfo::MethodInfo(const PropertyInfo &p_ret, StringName p_name, const Args &...args) :
|
||||||
name(p_name), return_val(p_ret), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
name(p_name), return_val(p_ret), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
||||||
arguments = { args... };
|
arguments = { args... };
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,8 @@ T *Object::cast_to(Object *p_object) {
|
||||||
if (p_object == nullptr) {
|
if (p_object == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));
|
StringName class_name = T::get_class_static();
|
||||||
|
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(class_name._native_ptr()));
|
||||||
if (casted == nullptr) {
|
if (casted == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,8 @@ const T *Object::cast_to(const Object *p_object) {
|
||||||
if (p_object == nullptr) {
|
if (p_object == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));
|
StringName class_name = T::get_class_static();
|
||||||
|
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(class_name._native_ptr()));
|
||||||
if (casted == nullptr) {
|
if (casted == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,15 @@ namespace godot {
|
||||||
|
|
||||||
struct PropertyInfo {
|
struct PropertyInfo {
|
||||||
Variant::Type type = Variant::NIL;
|
Variant::Type type = Variant::NIL;
|
||||||
String name;
|
StringName name;
|
||||||
String class_name;
|
StringName class_name;
|
||||||
uint32_t hint = 0;
|
uint32_t hint = 0;
|
||||||
String hint_string;
|
String hint_string;
|
||||||
uint32_t usage = 7;
|
uint32_t usage = 7;
|
||||||
|
|
||||||
PropertyInfo() = default;
|
PropertyInfo() = default;
|
||||||
|
|
||||||
PropertyInfo(Variant::Type p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
|
PropertyInfo(Variant::Type p_type, const StringName &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") :
|
||||||
type(p_type),
|
type(p_type),
|
||||||
name(p_name),
|
name(p_name),
|
||||||
hint(p_hint),
|
hint(p_hint),
|
||||||
|
@ -66,7 +66,7 @@ struct PropertyInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyInfo(GDNativeVariantType p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
|
PropertyInfo(GDNativeVariantType p_type, const StringName &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") :
|
||||||
PropertyInfo((Variant::Type)p_type, p_name, p_hint, p_hint_string, p_usage, p_class_name) {}
|
PropertyInfo((Variant::Type)p_type, p_name, p_hint, p_hint_string, p_usage, p_class_name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ struct TypeInherits {
|
||||||
!TypesAreSame<B volatile const, void volatile const>::value;
|
!TypesAreSame<B volatile const, void volatile const>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GDNativePropertyInfo make_property_info(GDNativeVariantType p_type, const char *p_name, uint32_t p_hint = PROPERTY_HINT_NONE, const char *p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const char *p_class_name = "") {
|
static PropertyInfo make_property_info(Variant::Type p_type, const StringName &p_name, uint32_t p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") {
|
||||||
GDNativePropertyInfo info;
|
PropertyInfo info;
|
||||||
info.type = p_type;
|
info.type = p_type;
|
||||||
info.name = p_name;
|
info.name = p_name;
|
||||||
info.hint = p_hint;
|
info.hint = p_hint;
|
||||||
|
@ -98,16 +98,16 @@ struct GetTypeInfo;
|
||||||
struct GetTypeInfo<m_type> { \
|
struct GetTypeInfo<m_type> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(VARIANT_TYPE, ""); \
|
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<const m_type &> { \
|
struct GetTypeInfo<const m_type &> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(VARIANT_TYPE, ""); \
|
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,16 +116,16 @@ struct GetTypeInfo;
|
||||||
struct GetTypeInfo<m_type> { \
|
struct GetTypeInfo<m_type> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(VARIANT_TYPE, ""); \
|
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<const m_type &> { \
|
struct GetTypeInfo<const m_type &> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(VARIANT_TYPE, ""); \
|
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,8 +182,8 @@ template <>
|
||||||
struct GetTypeInfo<Variant> {
|
struct GetTypeInfo<Variant> {
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
return make_property_info(Variant::Type::NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -191,8 +191,8 @@ template <>
|
||||||
struct GetTypeInfo<const Variant &> {
|
struct GetTypeInfo<const Variant &> {
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
return make_property_info(Variant::Type::NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -200,8 +200,8 @@ template <typename T>
|
||||||
struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
|
struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
|
||||||
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
|
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,19 +209,19 @@ template <typename T>
|
||||||
struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
|
struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
|
||||||
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
|
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
|
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<m_impl> { \
|
struct GetTypeInfo<m_impl> { \
|
||||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
|
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAKE_ENUM_TYPE_INFO(m_class, m_enum) \
|
#define MAKE_ENUM_TYPE_INFO(m_class, m_enum) \
|
||||||
|
@ -231,7 +231,7 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
|
||||||
TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, const m_class::m_enum &)
|
TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, const m_class::m_enum &)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const char *__constant_get_enum_name(T param, const char *p_constant) {
|
inline StringName __constant_get_enum_name(T param, StringName p_constant) {
|
||||||
if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
|
if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
|
||||||
ERR_PRINT(("Missing VARIANT_ENUM_CAST for constant's enum: " + String(p_constant)).utf8().get_data());
|
ERR_PRINT(("Missing VARIANT_ENUM_CAST for constant's enum: " + String(p_constant)).utf8().get_data());
|
||||||
}
|
}
|
||||||
|
@ -251,24 +251,24 @@ public:
|
||||||
_FORCE_INLINE_ operator Variant() const { return value; }
|
_FORCE_INLINE_ operator Variant() const { return value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
|
#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<m_impl> { \
|
struct GetTypeInfo<m_impl> { \
|
||||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
||||||
#m_class "." #m_enum); \
|
#m_class "." #m_enum); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<BitField<m_impl>> { \
|
struct GetTypeInfo<BitField<m_impl>> { \
|
||||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||||
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
||||||
#m_class "." #m_enum); \
|
#m_class "." #m_enum); \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAKE_BITFIELD_TYPE_INFO(m_class, m_enum) \
|
#define MAKE_BITFIELD_TYPE_INFO(m_class, m_enum) \
|
||||||
|
@ -309,8 +309,8 @@ template <typename T>
|
||||||
struct GetTypeInfo<TypedArray<T>> {
|
struct GetTypeInfo<TypedArray<T>> {
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
|
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -318,27 +318,27 @@ template <typename T>
|
||||||
struct GetTypeInfo<const TypedArray<T> &> {
|
struct GetTypeInfo<const TypedArray<T> &> {
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
||||||
static inline GDNativePropertyInfo get_class_info() {
|
static inline PropertyInfo get_class_info() {
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
|
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAKE_TYPED_ARRAY_INFO(m_type, m_variant_type) \
|
#define MAKE_TYPED_ARRAY_INFO(m_type, m_variant_type) \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<TypedArray<m_type>> { \
|
struct GetTypeInfo<TypedArray<m_type>> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
|
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
template <> \
|
template <> \
|
||||||
struct GetTypeInfo<const TypedArray<m_type> &> { \
|
struct GetTypeInfo<const TypedArray<m_type> &> { \
|
||||||
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
|
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
|
||||||
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
|
||||||
static inline GDNativePropertyInfo get_class_info() { \
|
static inline PropertyInfo get_class_info() { \
|
||||||
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
|
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
MAKE_TYPED_ARRAY_INFO(bool, Variant::BOOL)
|
MAKE_TYPED_ARRAY_INFO(bool, Variant::BOOL)
|
||||||
|
|
|
@ -36,20 +36,24 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
const StringName *Wrapped::_get_extension_class() const {
|
const StringName *Wrapped::_get_extension_class_name() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wrapped::_postinitialize() {
|
void Wrapped::_postinitialize() {
|
||||||
const StringName *extension_class = _get_extension_class();
|
const StringName *extension_class = _get_extension_class_name();
|
||||||
if (extension_class) {
|
if (extension_class) {
|
||||||
godot::internal::gdn_interface->object_set_instance(_owner, (void *)extension_class, this);
|
// TODO: replace C cast by a proper reinterpret_cast once `object_set_instance` signature correctly handles `const GDNativeStringNamePtr` param
|
||||||
|
// (see: https://github.com/godotengine/godot/pull/67751)
|
||||||
|
godot::internal::gdn_interface->object_set_instance(_owner, (GDNativeStringNamePtr)(extension_class), this);
|
||||||
}
|
}
|
||||||
godot::internal::gdn_interface->object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
|
godot::internal::gdn_interface->object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
|
||||||
}
|
}
|
||||||
|
|
||||||
Wrapped::Wrapped(const StringName p_godot_class) {
|
Wrapped::Wrapped(const StringName p_godot_class) {
|
||||||
_owner = godot::internal::gdn_interface->classdb_construct_object((void *)&p_godot_class);
|
// TODO: replace C cast by a proper reinterpret_cast once `classdb_construct_object` signature correctly handles `const GDNativeStringNamePtr` param
|
||||||
|
// (see: https://github.com/godotengine/godot/pull/67751)
|
||||||
|
_owner = godot::internal::gdn_interface->classdb_construct_object((GDNativeStringNamePtr)(p_godot_class._native_ptr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Wrapped::Wrapped(GodotObject *p_godot_object) {
|
Wrapped::Wrapped(GodotObject *p_godot_object) {
|
||||||
|
|
|
@ -39,40 +39,40 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
std::unordered_map<std::string, ClassDB::ClassInfo> ClassDB::classes;
|
std::unordered_map<StringName, ClassDB::ClassInfo> ClassDB::classes;
|
||||||
GDNativeInitializationLevel ClassDB::current_level = GDNATIVE_INITIALIZATION_CORE;
|
GDNativeInitializationLevel ClassDB::current_level = GDNATIVE_INITIALIZATION_CORE;
|
||||||
|
|
||||||
MethodDefinition D_METHOD(const char *p_name) {
|
MethodDefinition D_METHOD(StringName p_name) {
|
||||||
return MethodDefinition(p_name);
|
return MethodDefinition(p_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
|
MethodDefinition D_METHOD(StringName p_name, StringName p_arg1) {
|
||||||
MethodDefinition method(p_name);
|
MethodDefinition method(p_name);
|
||||||
method.args.push_front(p_arg1);
|
method.args.push_front(p_arg1);
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::add_property_group(const char *p_class, const char *p_name, const char *p_prefix) {
|
void ClassDB::add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix) {
|
||||||
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}{1}' to non-existing class '{2}'.").format(Array::make(p_prefix, p_name, p_class)));
|
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}{1}' to non-existing class '{2}'.").format(Array::make(p_prefix, p_name, p_class)));
|
||||||
|
|
||||||
internal::gdn_interface->classdb_register_extension_class_property_group(internal::library, p_class, p_name, p_prefix);
|
internal::gdn_interface->classdb_register_extension_class_property_group(internal::library, p_class._native_ptr(), p_name._native_ptr(), p_prefix._native_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::add_property_subgroup(const char *p_class, const char *p_name, const char *p_prefix) {
|
void ClassDB::add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix) {
|
||||||
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}{1}' to non-existing class '{2}'.").format(Array::make(p_prefix, p_name, p_class)));
|
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}{1}' to non-existing class '{2}'.").format(Array::make(p_prefix, p_name, p_class)));
|
||||||
|
|
||||||
internal::gdn_interface->classdb_register_extension_class_property_subgroup(internal::library, p_class, p_name, p_prefix);
|
internal::gdn_interface->classdb_register_extension_class_property_subgroup(internal::library, p_class._native_ptr(), p_name._native_ptr(), p_prefix._native_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::add_property(const char *p_class, const PropertyInfo &p_pinfo, const char *p_setter, const char *p_getter, int p_index) {
|
void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
|
||||||
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}' to non-existing class '{1}'.").format(Array::make(p_pinfo.name, p_class)));
|
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), String("Trying to add property '{0}' to non-existing class '{1}'.").format(Array::make(p_pinfo.name, p_class)));
|
||||||
|
|
||||||
ClassInfo &info = classes[p_class];
|
ClassInfo &info = classes[p_class];
|
||||||
|
|
||||||
ERR_FAIL_COND_MSG(info.property_names.find(p_pinfo.name.utf8().get_data()) != info.property_names.end(), String("Property '{0}' already exists in class '{1}'.").format(Array::make(p_pinfo.name, p_class)));
|
ERR_FAIL_COND_MSG(info.property_names.find(p_pinfo.name) != info.property_names.end(), String("Property '{0}' already exists in class '{1}'.").format(Array::make(p_pinfo.name, p_class)));
|
||||||
|
|
||||||
MethodBind *setter = nullptr;
|
MethodBind *setter = nullptr;
|
||||||
if (p_setter) {
|
if (p_setter != String("")) {
|
||||||
setter = get_method(p_class, p_setter);
|
setter = get_method(p_class, p_setter);
|
||||||
|
|
||||||
ERR_FAIL_COND_MSG(!setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
|
ERR_FAIL_COND_MSG(!setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
|
||||||
|
@ -81,7 +81,7 @@ void ClassDB::add_property(const char *p_class, const PropertyInfo &p_pinfo, con
|
||||||
ERR_FAIL_COND_MSG(exp_args != setter->get_argument_count(), String("Setter method '{0}::{1}()' must take a single argument.").format(Array::make(p_class, p_setter)));
|
ERR_FAIL_COND_MSG(exp_args != setter->get_argument_count(), String("Setter method '{0}::{1}()' must take a single argument.").format(Array::make(p_class, p_setter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_FAIL_COND_MSG(!p_getter, String("Getter method must be specified for '{0}::{1}'.").format(Array::make(p_class, p_pinfo.name)));
|
ERR_FAIL_COND_MSG(p_getter == String(""), String("Getter method must be specified for '{0}::{1}'.").format(Array::make(p_class, p_pinfo.name)));
|
||||||
|
|
||||||
MethodBind *getter = get_method(p_class, p_getter);
|
MethodBind *getter = get_method(p_class, p_getter);
|
||||||
ERR_FAIL_COND_MSG(!getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
|
ERR_FAIL_COND_MSG(!getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
|
||||||
|
@ -91,15 +91,15 @@ void ClassDB::add_property(const char *p_class, const PropertyInfo &p_pinfo, con
|
||||||
}
|
}
|
||||||
|
|
||||||
// register property with plugin
|
// register property with plugin
|
||||||
info.property_names.insert(p_pinfo.name.utf8().get_data());
|
info.property_names.insert(p_pinfo.name);
|
||||||
|
|
||||||
// register with Godot
|
// register with Godot
|
||||||
GDNativePropertyInfo prop_info = {
|
GDNativePropertyInfo prop_info = {
|
||||||
static_cast<GDNativeVariantType>(p_pinfo.type), // GDNativeVariantType type;
|
static_cast<GDNativeVariantType>(p_pinfo.type), // GDNativeVariantType type;
|
||||||
_alloc_and_copy_cstr(p_pinfo.name.utf8().get_data()), // const char *name;
|
p_pinfo.name._native_ptr(), // GDNativeStringNamePtr name;
|
||||||
_alloc_and_copy_cstr(p_pinfo.class_name.utf8().get_data()), // const char *class_name;
|
p_pinfo.class_name._native_ptr(), // GDNativeStringNamePtr class_name;
|
||||||
p_pinfo.hint, // NONE //uint32_t hint;
|
p_pinfo.hint, // NONE //uint32_t hint;
|
||||||
_alloc_and_copy_cstr(p_pinfo.hint_string.utf8().get_data()), // const char *hint_string;
|
p_pinfo.hint_string._native_ptr(), // GDNativeStringPtr hint_string;
|
||||||
p_pinfo.usage, // DEFAULT //uint32_t usage;
|
p_pinfo.usage, // DEFAULT //uint32_t usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -111,19 +111,15 @@ void ClassDB::add_property(const char *p_class, const PropertyInfo &p_pinfo, con
|
||||||
setget.index = p_index;
|
setget.index = p_index;
|
||||||
setget.type = p_pinfo.type;
|
setget.type = p_pinfo.type;
|
||||||
|
|
||||||
internal::gdn_interface->classdb_register_extension_class_property(internal::library, info.name, &prop_info, setget.setter, setget.getter);
|
internal::gdn_interface->classdb_register_extension_class_property(internal::library, info.name._native_ptr(), &prop_info, setget.setter._native_ptr(), setget.getter._native_ptr());
|
||||||
|
|
||||||
memfree(const_cast<char *>(prop_info.name));
|
|
||||||
memfree(const_cast<char *>(prop_info.class_name));
|
|
||||||
memfree(const_cast<char *>(prop_info.hint_string));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodBind *ClassDB::get_method(const char *p_class, const char *p_method) {
|
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(p_class));
|
||||||
|
|
||||||
ClassInfo *type = &classes[p_class];
|
ClassInfo *type = &classes[p_class];
|
||||||
while (type) {
|
while (type) {
|
||||||
std::unordered_map<std::string, MethodBind *>::iterator method = type->method_map.find(p_method);
|
std::unordered_map<StringName, MethodBind *>::iterator method = type->method_map.find(p_method);
|
||||||
if (method != type->method_map.end()) {
|
if (method != type->method_map.end()) {
|
||||||
return method->second;
|
return method->second;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +131,9 @@ MethodBind *ClassDB::get_method(const char *p_class, const char *p_method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount) {
|
MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount) {
|
||||||
const char *instance_type = p_bind->get_instance_class();
|
StringName instance_type = p_bind->get_instance_class();
|
||||||
|
|
||||||
std::unordered_map<std::string, ClassInfo>::iterator type_it = classes.find(instance_type);
|
std::unordered_map<StringName, ClassInfo>::iterator type_it = classes.find(instance_type);
|
||||||
if (type_it == classes.end()) {
|
if (type_it == classes.end()) {
|
||||||
memdelete(p_bind);
|
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(instance_type));
|
||||||
|
@ -164,10 +160,10 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const M
|
||||||
|
|
||||||
p_bind->set_hint_flags(p_flags);
|
p_bind->set_hint_flags(p_flags);
|
||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<StringName> args;
|
||||||
args.resize(method_name.args.size());
|
args.resize(method_name.args.size());
|
||||||
size_t arg_index = 0;
|
size_t arg_index = 0;
|
||||||
for (std::string arg : method_name.args) {
|
for (StringName arg : method_name.args) {
|
||||||
args[arg_index++] = arg;
|
args[arg_index++] = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,34 +188,57 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const M
|
||||||
return p_bind;
|
return p_bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::bind_method_godot(const char *p_class_name, MethodBind *p_method) {
|
void ClassDB::bind_method_godot(const StringName &p_class_name, MethodBind *p_method) {
|
||||||
std::vector<GDNativeVariantPtr> def_args;
|
std::vector<GDNativeVariantPtr> def_args;
|
||||||
const std::vector<Variant> &def_args_val = p_method->get_default_arguments();
|
const std::vector<Variant> &def_args_val = p_method->get_default_arguments();
|
||||||
|
|
||||||
def_args.resize(def_args_val.size());
|
def_args.resize(def_args_val.size());
|
||||||
for (int i = 0; i < def_args_val.size(); i++) {
|
for (int i = 0; i < def_args_val.size(); i++) {
|
||||||
def_args[i] = (GDNativeVariantPtr)&def_args_val[i];
|
def_args[i] = (GDNativeVariantPtr)&def_args_val[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<PropertyInfo> return_value_and_arguments_info = p_method->get_arguments_info_list();
|
||||||
|
std::vector<GDNativeExtensionClassMethodArgumentMetadata> return_value_and_arguments_metadata = p_method->get_arguments_metadata_list();
|
||||||
|
|
||||||
|
std::vector<GDNativePropertyInfo> return_value_and_arguments_gdnative_info;
|
||||||
|
return_value_and_arguments_gdnative_info.reserve(return_value_and_arguments_info.size());
|
||||||
|
for (std::vector<PropertyInfo>::iterator it = return_value_and_arguments_info.begin(); it != return_value_and_arguments_info.end(); it++) {
|
||||||
|
return_value_and_arguments_gdnative_info.push_back(
|
||||||
|
GDNativePropertyInfo{
|
||||||
|
static_cast<GDNativeVariantType>(it->type), // GDNativeVariantType type;
|
||||||
|
it->name._native_ptr(), // GDNativeStringNamePtr name;
|
||||||
|
it->class_name._native_ptr(), // GDNativeStringNamePtr class_name;
|
||||||
|
it->hint, // uint32_t hint;
|
||||||
|
it->hint_string._native_ptr(), // GDNativeStringPtr hint_string;
|
||||||
|
it->usage, // uint32_t usage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
GDNativePropertyInfo *return_value_info = return_value_and_arguments_gdnative_info.data();
|
||||||
|
GDNativeExtensionClassMethodArgumentMetadata *return_value_metadata = return_value_and_arguments_metadata.data();
|
||||||
|
GDNativePropertyInfo *arguments_info = return_value_and_arguments_gdnative_info.data() + 1;
|
||||||
|
GDNativeExtensionClassMethodArgumentMetadata *arguments_metadata = return_value_and_arguments_metadata.data() + 1;
|
||||||
|
|
||||||
|
StringName name = p_method->get_name();
|
||||||
GDNativeExtensionClassMethodInfo method_info = {
|
GDNativeExtensionClassMethodInfo method_info = {
|
||||||
p_method->get_name(), // const char *name;
|
name._native_ptr(), // const GDNativeStringNamePtr;
|
||||||
p_method, // void *method_userdata;
|
p_method, // void *method_userdata;
|
||||||
MethodBind::bind_call, // GDNativeExtensionClassMethodCall call_func;
|
MethodBind::bind_call, // GDNativeExtensionClassMethodCall call_func;
|
||||||
MethodBind::bind_ptrcall, // GDNativeExtensionClassMethodPtrCall ptrcall_func;
|
MethodBind::bind_ptrcall, // GDNativeExtensionClassMethodPtrCall ptrcall_func;
|
||||||
p_method->get_hint_flags(), // uint32_t method_flags; /* GDNativeExtensionClassMethodFlags */
|
p_method->get_hint_flags(), // uint32_t method_flags; /* GDNativeExtensionClassMethodFlags */
|
||||||
(uint32_t)p_method->get_argument_count(), // uint32_t argument_count;
|
(uint32_t)p_method->get_argument_count(), // uint32_t argument_count;
|
||||||
(GDNativeBool)p_method->has_return(), // GDNativeBool has_return_value;
|
(GDNativeBool)p_method->has_return(), // GDNativeBool has_return_value;
|
||||||
MethodBind::bind_get_argument_type, //(GDNativeExtensionClassMethodGetArgumentType) get_argument_type_func;
|
return_value_info, // GDNativePropertyInfo *
|
||||||
MethodBind::bind_get_argument_info, // GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; /* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */
|
*return_value_metadata, // GDNativeExtensionClassMethodArgumentMetadata *
|
||||||
MethodBind::bind_get_argument_metadata, // GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func;
|
arguments_info, // GDNativePropertyInfo *
|
||||||
|
arguments_metadata, // GDNativeExtensionClassMethodArgumentMetadata *
|
||||||
(uint32_t)p_method->get_default_argument_count(), // uint32_t default_argument_count;
|
(uint32_t)p_method->get_default_argument_count(), // uint32_t default_argument_count;
|
||||||
def_args.data(), // GDNativeVariantPtr *default_arguments;
|
def_args.data(), // GDNativeVariantPtr *default_arguments;
|
||||||
};
|
};
|
||||||
internal::gdn_interface->classdb_register_extension_class_method(internal::library, p_class_name, &method_info);
|
internal::gdn_interface->classdb_register_extension_class_method(internal::library, p_class_name._native_ptr(), &method_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::add_signal(const char *p_class, const MethodInfo &p_signal) {
|
void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal) {
|
||||||
std::unordered_map<std::string, ClassInfo>::iterator type_it = classes.find(p_class);
|
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(p_class));
|
||||||
|
|
||||||
|
@ -242,25 +261,19 @@ void ClassDB::add_signal(const char *p_class, const MethodInfo &p_signal) {
|
||||||
for (const PropertyInfo &par : p_signal.arguments) {
|
for (const PropertyInfo &par : p_signal.arguments) {
|
||||||
parameters.push_back(GDNativePropertyInfo{
|
parameters.push_back(GDNativePropertyInfo{
|
||||||
static_cast<GDNativeVariantType>(par.type), // GDNativeVariantType type;
|
static_cast<GDNativeVariantType>(par.type), // GDNativeVariantType type;
|
||||||
_alloc_and_copy_cstr(par.name.utf8().get_data()), // const char *name;
|
par.name._native_ptr(), // const GDNativeStringNamePtr name;
|
||||||
_alloc_and_copy_cstr(par.class_name.utf8().get_data()), // const char *class_name;
|
par.class_name._native_ptr(), // const GDNativeStringNamePtr class_name;
|
||||||
par.hint, // NONE //uint32_t hint;
|
par.hint, // NONE //uint32_t hint;
|
||||||
_alloc_and_copy_cstr(par.hint_string.utf8().get_data()), // const char *hint_string;
|
par.hint_string._native_ptr(), // const GDNativeStringPtr hint_string;
|
||||||
par.usage, // DEFAULT //uint32_t usage;
|
par.usage, // DEFAULT //uint32_t usage;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal::gdn_interface->classdb_register_extension_class_signal(internal::library, cl.name, p_signal.name, parameters.data(), parameters.size());
|
internal::gdn_interface->classdb_register_extension_class_signal(internal::library, cl.name._native_ptr(), p_signal.name._native_ptr(), parameters.data(), parameters.size());
|
||||||
|
|
||||||
for (GDNativePropertyInfo &par : parameters) {
|
|
||||||
memfree(const_cast<char *>(par.name));
|
|
||||||
memfree(const_cast<char *>(par.class_name));
|
|
||||||
memfree(const_cast<char *>(par.hint_string));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::bind_integer_constant(const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield) {
|
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<std::string, ClassInfo>::iterator type_it = classes.find(p_class_name);
|
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(p_class_name));
|
||||||
|
|
||||||
|
@ -273,24 +286,23 @@ void ClassDB::bind_integer_constant(const char *p_class_name, const char *p_enum
|
||||||
type.constant_names.insert(p_constant_name);
|
type.constant_names.insert(p_constant_name);
|
||||||
|
|
||||||
// Register it with Godot
|
// Register it with Godot
|
||||||
internal::gdn_interface->classdb_register_extension_class_integer_constant(internal::library, p_class_name, p_enum_name, p_constant_name, p_constant_value, p_is_bitfield);
|
internal::gdn_interface->classdb_register_extension_class_integer_constant(internal::library, p_class_name._native_ptr(), p_enum_name._native_ptr(), p_constant_name._native_ptr(), p_constant_value, p_is_bitfield);
|
||||||
}
|
}
|
||||||
|
GDNativeExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, const GDNativeStringNamePtr p_name) {
|
||||||
GDNativeExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, const char *p_name) {
|
|
||||||
// This is called by Godot the first time it calls a virtual function, and it caches the result, per object instance.
|
// This is called by Godot the first time it calls a virtual function, and it caches the result, per object instance.
|
||||||
// Because of this, it can happen from different threads at once.
|
// Because of this, it can happen from different threads at once.
|
||||||
// It should be ok not using any mutex as long as we only READ data.
|
// It should be ok not using any mutex as long as we only READ data.
|
||||||
|
const StringName *class_name = reinterpret_cast<const StringName *>(p_userdata);
|
||||||
|
const StringName *name = reinterpret_cast<const StringName *>(p_name);
|
||||||
|
|
||||||
const char *class_name = (const char *)p_userdata;
|
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));
|
||||||
std::unordered_map<std::string, 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));
|
|
||||||
|
|
||||||
const ClassInfo *type = &type_it->second;
|
const ClassInfo *type = &type_it->second;
|
||||||
|
|
||||||
// Find method in current class, or any of its parent classes (Godot classes not included)
|
// Find method in current class, or any of its parent classes (Godot classes not included)
|
||||||
while (type != nullptr) {
|
while (type != nullptr) {
|
||||||
std::unordered_map<std::string, GDNativeExtensionClassCallVirtual>::const_iterator method_it = type->virtual_methods.find(p_name);
|
std::unordered_map<StringName, GDNativeExtensionClassCallVirtual>::const_iterator method_it = type->virtual_methods.find(*name);
|
||||||
|
|
||||||
if (method_it != type->virtual_methods.end()) {
|
if (method_it != type->virtual_methods.end()) {
|
||||||
return method_it->second;
|
return method_it->second;
|
||||||
|
@ -302,8 +314,8 @@ GDNativeExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, co
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::bind_virtual_method(const char *p_class, const char *p_method, GDNativeExtensionClassCallVirtual p_call) {
|
void ClassDB::bind_virtual_method(const StringName &p_class, const StringName &p_method, GDNativeExtensionClassCallVirtual p_call) {
|
||||||
std::unordered_map<std::string, ClassInfo>::iterator type_it = classes.find(p_class);
|
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(p_class));
|
||||||
|
|
||||||
ClassInfo &type = type_it->second;
|
ClassInfo &type = type_it->second;
|
||||||
|
@ -318,7 +330,7 @@ void ClassDB::initialize_class(const ClassInfo &p_cl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::initialize(GDNativeInitializationLevel p_level) {
|
void ClassDB::initialize(GDNativeInitializationLevel p_level) {
|
||||||
for (const std::pair<std::string, ClassInfo> pair : classes) {
|
for (const std::pair<StringName, ClassInfo> pair : classes) {
|
||||||
const ClassInfo &cl = pair.second;
|
const ClassInfo &cl = pair.second;
|
||||||
if (cl.level != p_level) {
|
if (cl.level != p_level) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -329,13 +341,13 @@ void ClassDB::initialize(GDNativeInitializationLevel p_level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassDB::deinitialize(GDNativeInitializationLevel p_level) {
|
void ClassDB::deinitialize(GDNativeInitializationLevel p_level) {
|
||||||
for (const std::pair<std::string, ClassInfo> pair : classes) {
|
for (const std::pair<StringName, ClassInfo> pair : classes) {
|
||||||
const ClassInfo &cl = pair.second;
|
const ClassInfo &cl = pair.second;
|
||||||
if (cl.level != p_level) {
|
if (cl.level != p_level) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal::gdn_interface->classdb_unregister_extension_class(internal::library, cl.name);
|
internal::gdn_interface->classdb_unregister_extension_class(internal::library, cl.name._native_ptr());
|
||||||
|
|
||||||
for (auto method : cl.method_map) {
|
for (auto method : cl.method_map) {
|
||||||
memdelete(method.second);
|
memdelete(method.second);
|
||||||
|
|
|
@ -32,11 +32,11 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
const char *MethodBind::get_name() const {
|
StringName MethodBind::get_name() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodBind::set_name(const char *p_name) {
|
void MethodBind::set_name(const StringName &p_name) {
|
||||||
name = p_name;
|
name = p_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +60,11 @@ void MethodBind::set_vararg(bool p_vararg) {
|
||||||
_vararg = p_vararg;
|
_vararg = p_vararg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MethodBind::set_argument_names(const std::vector<std::string> &p_names) {
|
void MethodBind::set_argument_names(const std::vector<StringName> &p_names) {
|
||||||
argument_names = p_names;
|
argument_names = p_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> MethodBind::get_argument_names() const {
|
std::vector<StringName> MethodBind::get_argument_names() const {
|
||||||
return argument_names;
|
return argument_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,29 +83,14 @@ void MethodBind::generate_argument_types(int p_count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GDNativePropertyInfo MethodBind::get_argument_info(int p_argument) const {
|
PropertyInfo MethodBind::get_argument_info(int p_argument) const {
|
||||||
GDNativePropertyInfo info = gen_argument_type_info(p_argument);
|
PropertyInfo info = gen_argument_type_info(p_argument);
|
||||||
if (p_argument >= 0) {
|
if (p_argument >= 0) {
|
||||||
info.name = p_argument < (int)argument_names.size() ? argument_names[p_argument].c_str() : "";
|
info.name = p_argument < (int)argument_names.size() ? argument_names[p_argument] : "";
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDNativeVariantType MethodBind::bind_get_argument_type(void *p_method_userdata, int32_t p_argument) {
|
|
||||||
const MethodBind *bind = reinterpret_cast<const MethodBind *>(p_method_userdata);
|
|
||||||
return bind->get_argument_type(p_argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MethodBind::bind_get_argument_info(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info) {
|
|
||||||
const MethodBind *bind = reinterpret_cast<const MethodBind *>(p_method_userdata);
|
|
||||||
*r_info = bind->get_argument_info(p_argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
GDNativeExtensionClassMethodArgumentMetadata MethodBind::bind_get_argument_metadata(void *p_method_userdata, int32_t p_argument) {
|
|
||||||
const MethodBind *bind = reinterpret_cast<const MethodBind *>(p_method_userdata);
|
|
||||||
return bind->get_argument_metadata(p_argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MethodBind::bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
|
void MethodBind::bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
|
||||||
const MethodBind *bind = reinterpret_cast<const MethodBind *>(p_method_userdata);
|
const MethodBind *bind = reinterpret_cast<const MethodBind *>(p_method_userdata);
|
||||||
Variant ret = bind->call(p_instance, p_args, p_argument_count, *r_error);
|
Variant ret = bind->call(p_instance, p_args, p_argument_count, *r_error);
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace godot {
|
||||||
MethodInfo::MethodInfo() :
|
MethodInfo::MethodInfo() :
|
||||||
flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
||||||
|
|
||||||
MethodInfo::MethodInfo(const char *p_name) :
|
MethodInfo::MethodInfo(StringName p_name) :
|
||||||
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
||||||
|
|
||||||
MethodInfo::MethodInfo(Variant::Type ret) :
|
MethodInfo::MethodInfo(Variant::Type ret) :
|
||||||
|
@ -43,12 +43,12 @@ MethodInfo::MethodInfo(Variant::Type ret) :
|
||||||
return_val.type = ret;
|
return_val.type = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodInfo::MethodInfo(Variant::Type ret, const char *p_name) :
|
MethodInfo::MethodInfo(Variant::Type ret, StringName p_name) :
|
||||||
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
|
||||||
return_val.type = ret;
|
return_val.type = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodInfo::MethodInfo(const PropertyInfo &p_ret, const char *p_name) :
|
MethodInfo::MethodInfo(const PropertyInfo &p_ret, StringName p_name) :
|
||||||
name(p_name), return_val(p_ret), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
name(p_name), return_val(p_ret), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {}
|
||||||
|
|
||||||
} // namespace godot
|
} // namespace godot
|
||||||
|
|
Loading…
Reference in New Issue