From 70755d873b7f4832fecfb20ba4c7d99b20e30e95 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 6 May 2022 09:44:13 +0300 Subject: [GDExtension] Fix static method binds and default arguments. --- core/extension/native_extension.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core/extension') diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 441bdd2ac4..db1cbd53b4 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -74,7 +74,7 @@ public: virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) override { Variant ret; - GDExtensionClassInstancePtr extension_instance = p_object->_get_extension_instance(); + GDExtensionClassInstancePtr extension_instance = is_static() ? nullptr : p_object->_get_extension_instance(); 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); @@ -91,6 +91,7 @@ public: virtual bool is_vararg() const override { return false; } + explicit NativeExtensionMethodBind(const GDNativeExtensionClassMethodInfo *p_method_info) { method_userdata = p_method_info->method_userdata; call_func = p_method_info->call_func; @@ -100,14 +101,24 @@ public: get_argument_metadata_func = p_method_info->get_argument_metadata_func; set_name(p_method_info->name); - vararg = p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_VARARG; + set_hint_flags(p_method_info->method_flags); + vararg = p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_VARARG; _set_returns(p_method_info->has_return_value); _set_const(p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_CONST); + _set_static(p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_STATIC); #ifdef DEBUG_METHODS_ENABLED _generate_argument_types(p_method_info->argument_count); #endif set_argument_count(p_method_info->argument_count); + + Vector defargs; + defargs.resize(p_method_info->default_argument_count); + for (uint32_t i = 0; i < p_method_info->default_argument_count; i++) { + defargs.write[i] = *static_cast(p_method_info->default_arguments[i]); + } + + set_default_arguments(defargs); } }; -- cgit v1.2.3