summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-05-06 09:44:13 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-05-06 10:06:12 +0300
commit70755d873b7f4832fecfb20ba4c7d99b20e30e95 (patch)
tree90e255ea6e74d11fcd097f982c77318e3b91c1ec
parentf4ece7e7361ae5e23a80743c9184ac584ad2ce76 (diff)
[GDExtension] Fix static method binds and default arguments.
-rw-r--r--core/extension/native_extension.cpp15
1 files changed, 13 insertions, 2 deletions
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<Variant> 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<Variant *>(p_method_info->default_arguments[i]);
+ }
+
+ set_default_arguments(defargs);
}
};