diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-18 08:05:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 08:05:02 +0200 |
commit | 17ce4846ff6d14464d87f62bd1ea05176eeaf6ca (patch) | |
tree | 7e8d186c1ca34316d48195e91e4592a23893f846 /core | |
parent | 4603d5dbf9fc7ef35889f5f62c9afa8b16701417 (diff) | |
parent | 3b593b596e2fadb2dd3be3fa772c208ce1bb5ed4 (diff) |
Merge pull request #51807 from vnen/extension-fixes
Some fixes for the extension API
Diffstat (limited to 'core')
-rw-r--r-- | core/extension/gdnative_interface.cpp | 19 | ||||
-rw-r--r-- | core/extension/gdnative_interface.h | 5 | ||||
-rw-r--r-- | core/extension/native_extension.cpp | 5 | ||||
-rw-r--r-- | core/extension/native_extension.h | 2 | ||||
-rw-r--r-- | core/object/make_virtuals.py | 2 |
5 files changed, 26 insertions, 7 deletions
diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index e0ebd19376..de107b4156 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -663,7 +663,23 @@ static const char32_t *gdnative_string_operator_index_const(const GDNativeString /* OBJECT API */ -static void gdnative_object_method_bind_ptrcall(GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr p_ret) { +static void gdnative_object_method_bind_call(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeVariantPtr *p_args, GDNativeInt p_arg_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error) { + MethodBind *mb = (MethodBind *)p_method_bind; + Object *o = (Object *)p_instance; + const Variant **args = (const Variant **)p_args; + Callable::CallError error; + + Variant ret = mb->call(o, args, p_arg_count, error); + memnew_placement(r_return, Variant(ret)); + + if (r_error) { + r_error->error = (GDNativeCallErrorType)(error.error); + r_error->argument = error.argument; + r_error->expected = error.expected; + } +} + +static void gdnative_object_method_bind_ptrcall(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr p_ret) { MethodBind *mb = (MethodBind *)p_method_bind; Object *o = (Object *)p_instance; mb->ptrcall(o, (const void **)p_args, p_ret); @@ -829,6 +845,7 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) { /* OBJECT */ + gdni.object_method_bind_call = gdnative_object_method_bind_call; gdni.object_method_bind_ptrcall = gdnative_object_method_bind_ptrcall; gdni.object_destroy = gdnative_object_destroy; gdni.global_get_singleton = gdnative_global_get_singleton; diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index 3432d8fabe..3a5b04429c 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -389,7 +389,8 @@ typedef struct { /* OBJECT */ - void (*object_method_bind_ptrcall)(GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); + void (*object_method_bind_call)(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeVariantPtr *p_args, GDNativeInt p_arg_count, GDNativeVariantPtr r_ret, GDNativeCallError *r_error); + void (*object_method_bind_ptrcall)(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); void (*object_destroy)(GDNativeObjectPtr p_o); GDNativeObjectPtr (*global_get_singleton)(const char *p_name); void *(*object_get_instance_binding)(GDNativeObjectPtr p_o, void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks); @@ -409,7 +410,7 @@ typedef struct { 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); 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_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_enum_name, const char *p_class_name, const char *p_constant_name, uint32_t p_constant_value); + 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); 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_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_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. */ diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 91d304627a..0556c9c84d 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -69,7 +69,7 @@ public: virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { Variant ret; GDExtensionClassInstancePtr extension_instance = p_object->_get_extension_instance(); - GDNativeCallError ce; + GDNativeCallError ce{ GDNATIVE_CALL_OK, 0, 0 }; call_func(method_userdata, extension_instance, (const GDNativeVariantPtr *)p_args, p_arg_count, (GDNativeVariantPtr)&ret, &ce); r_error.error = Callable::CallError::Error(ce.error); r_error.argument = ce.argument; @@ -154,6 +154,7 @@ void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibr extension->native_extension.create_instance = p_extension_funcs->create_instance_func; extension->native_extension.set_object_instance = p_extension_funcs->object_instance_func; extension->native_extension.free_instance = p_extension_funcs->free_instance_func; + extension->native_extension.get_virtual = p_extension_funcs->get_virtual_func; ClassDB::register_extension_class(&extension->native_extension); } @@ -171,7 +172,7 @@ void NativeExtension::_register_extension_class_method(const GDNativeExtensionCl ClassDB::bind_method_custom(class_name, method); } -void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, uint32_t p_constant_value) { +void NativeExtension::_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) { NativeExtension *self = (NativeExtension *)p_library; StringName class_name = p_class_name; diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h index 8bd95b2867..a961b21cc9 100644 --- a/core/extension/native_extension.h +++ b/core/extension/native_extension.h @@ -48,7 +48,7 @@ class NativeExtension : public Resource { static void _register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); static void _register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); - static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, uint32_t p_constant_value); + static void _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); static void _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); static void _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); static void _unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index 2c6b8cddc9..9948620c73 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -1,8 +1,8 @@ proto = """ #define GDVIRTUAL$VER($RET m_name $ARG) \\ -GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ StringName _gdvirtual_##m_name##_sn = #m_name;\\ bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ + GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ ScriptInstance *script_instance = ((Object*)(this))->get_script_instance();\\ if (script_instance) {\\ Callable::CallError ce; \\ |