2023-01-10 15:14:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* method_bind.hpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#ifndef GODOT_METHOD_BIND_HPP
|
|
|
|
#define GODOT_METHOD_BIND_HPP
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
#include <godot_cpp/core/binder_common.hpp>
|
|
|
|
#include <godot_cpp/core/type_info.hpp>
|
|
|
|
|
|
|
|
#include <godot_cpp/core/memory.hpp>
|
|
|
|
|
2022-12-13 23:40:17 +00:00
|
|
|
#include <gdextension_interface.h>
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
#include <godot_cpp/classes/global_constants.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
|
|
|
class MethodBind {
|
2022-10-22 17:42:48 +00:00
|
|
|
StringName name;
|
|
|
|
StringName instance_class;
|
2021-08-18 14:03:52 +00:00
|
|
|
int argument_count = 0;
|
|
|
|
uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
|
|
|
|
|
2022-05-04 11:27:08 +00:00
|
|
|
bool _static = false;
|
2021-08-18 14:03:52 +00:00
|
|
|
bool _is_const = false;
|
|
|
|
bool _has_return = false;
|
2022-05-04 11:27:08 +00:00
|
|
|
bool _vararg = false;
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
std::vector<StringName> argument_names;
|
2022-12-07 13:11:44 +00:00
|
|
|
GDExtensionVariantType *argument_types = nullptr;
|
2021-08-18 14:03:52 +00:00
|
|
|
std::vector<Variant> default_arguments;
|
|
|
|
|
|
|
|
protected:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const = 0;
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const = 0;
|
2021-08-18 14:03:52 +00:00
|
|
|
void generate_argument_types(int p_count);
|
|
|
|
void set_const(bool p_const);
|
|
|
|
void set_return(bool p_return);
|
2022-05-04 11:27:08 +00:00
|
|
|
void set_static(bool p_static);
|
|
|
|
void set_vararg(bool p_vararg);
|
2021-08-18 14:03:52 +00:00
|
|
|
void set_argument_count(int p_count);
|
|
|
|
|
|
|
|
public:
|
2022-10-22 17:42:48 +00:00
|
|
|
StringName get_name() const;
|
|
|
|
void set_name(const StringName &p_name);
|
2021-11-12 10:03:29 +00:00
|
|
|
_FORCE_INLINE_ int get_default_argument_count() const { return (int)default_arguments.size(); }
|
2021-08-18 14:03:52 +00:00
|
|
|
_FORCE_INLINE_ const std::vector<Variant> &get_default_arguments() const { return default_arguments; }
|
|
|
|
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
|
2023-01-19 12:40:18 +00:00
|
|
|
const int num_default_args = (int)(default_arguments.size());
|
|
|
|
const int idx = p_arg - (argument_count - num_default_args);
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2023-01-19 12:40:18 +00:00
|
|
|
if (idx < 0 || idx >= num_default_args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ Variant get_default_argument(int p_arg) const {
|
2023-01-19 12:40:18 +00:00
|
|
|
const int num_default_args = (int)(default_arguments.size());
|
|
|
|
const int idx = p_arg - (argument_count - num_default_args);
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2023-01-19 12:40:18 +00:00
|
|
|
if (idx < 0 || idx >= num_default_args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
return Variant();
|
|
|
|
} else {
|
|
|
|
return default_arguments[idx];
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 17:42:48 +00:00
|
|
|
_FORCE_INLINE_ StringName get_instance_class() const { return instance_class; }
|
|
|
|
_FORCE_INLINE_ void set_instance_class(StringName p_class) { instance_class = p_class; }
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-11-18 18:33:28 +00:00
|
|
|
_FORCE_INLINE_ int get_argument_count() const { return argument_count; }
|
2021-08-18 14:03:52 +00:00
|
|
|
_FORCE_INLINE_ bool is_const() const { return _is_const; }
|
2022-05-04 11:27:08 +00:00
|
|
|
_FORCE_INLINE_ bool is_static() const { return _static; }
|
|
|
|
_FORCE_INLINE_ bool is_vararg() const { return _vararg; }
|
2021-08-18 14:03:52 +00:00
|
|
|
_FORCE_INLINE_ bool has_return() const { return _has_return; }
|
2022-12-07 13:11:44 +00:00
|
|
|
_FORCE_INLINE_ uint32_t get_hint_flags() const { return hint_flags | (is_const() ? GDEXTENSION_METHOD_FLAG_CONST : 0) | (is_vararg() ? GDEXTENSION_METHOD_FLAG_VARARG : 0) | (is_static() ? GDEXTENSION_METHOD_FLAG_STATIC : 0); }
|
2021-08-18 14:03:52 +00:00
|
|
|
_FORCE_INLINE_ void set_hint_flags(uint32_t p_hint_flags) { hint_flags = p_hint_flags; }
|
2022-10-22 17:42:48 +00:00
|
|
|
void set_argument_names(const std::vector<StringName> &p_names);
|
|
|
|
std::vector<StringName> get_argument_names() const;
|
2021-08-18 14:03:52 +00:00
|
|
|
void set_default_arguments(const std::vector<Variant> &p_default_arguments) { default_arguments = p_default_arguments; }
|
|
|
|
|
2022-12-07 13:11:44 +00:00
|
|
|
_FORCE_INLINE_ GDExtensionVariantType get_argument_type(int p_argument) const {
|
|
|
|
ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, GDEXTENSION_VARIANT_TYPE_NIL);
|
2021-08-18 14:03:52 +00:00
|
|
|
return argument_types[p_argument + 1];
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo get_argument_info(int p_argument) const;
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const = 0;
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
std::vector<PropertyInfo> get_arguments_info_list() const {
|
|
|
|
std::vector<PropertyInfo> vec;
|
|
|
|
// First element is return value
|
|
|
|
vec.reserve(argument_count + 1);
|
2022-10-23 20:31:57 +00:00
|
|
|
for (int i = 0; i < argument_count + 1; i++) {
|
2022-10-22 17:42:48 +00:00
|
|
|
vec.push_back(get_argument_info(i - 1));
|
|
|
|
}
|
|
|
|
return vec;
|
|
|
|
}
|
2022-12-07 13:11:44 +00:00
|
|
|
std::vector<GDExtensionClassMethodArgumentMetadata> get_arguments_metadata_list() const {
|
|
|
|
std::vector<GDExtensionClassMethodArgumentMetadata> vec;
|
2022-10-22 17:42:48 +00:00
|
|
|
// First element is return value
|
|
|
|
vec.reserve(argument_count + 1);
|
2024-06-27 16:40:29 +00:00
|
|
|
for (int i = 0; i < argument_count + 1; i++) {
|
2022-10-22 17:42:48 +00:00
|
|
|
vec.push_back(get_argument_metadata(i - 1));
|
|
|
|
}
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const = 0;
|
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_return) const = 0;
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
static void bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error);
|
|
|
|
static void bind_ptrcall(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_return);
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
virtual ~MethodBind();
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename Derived, typename T, typename R, bool should_returns>
|
2022-03-29 11:44:07 +00:00
|
|
|
class MethodBindVarArgBase : public MethodBind {
|
2021-08-18 14:03:52 +00:00
|
|
|
protected:
|
2022-03-29 11:44:07 +00:00
|
|
|
R(T::*method)
|
2022-12-07 13:11:44 +00:00
|
|
|
(const Variant **, GDExtensionInt, GDExtensionCallError &);
|
2022-10-22 17:42:48 +00:00
|
|
|
std::vector<PropertyInfo> arguments;
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
public:
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg < 0) {
|
2022-03-29 11:44:07 +00:00
|
|
|
return _gen_return_type_info();
|
2023-01-19 12:40:18 +00:00
|
|
|
} else if ((size_t)(p_arg) < arguments.size()) {
|
2022-09-02 07:41:24 +00:00
|
|
|
return arguments[p_arg];
|
2021-08-18 14:03:52 +00:00
|
|
|
} else {
|
2022-10-22 17:42:48 +00:00
|
|
|
return make_property_info(Variant::Type::NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
|
|
|
return static_cast<GDExtensionVariantType>(gen_argument_type_info(p_arg).type);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int) const {
|
|
|
|
return GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_return) const {
|
2022-03-29 11:44:07 +00:00
|
|
|
ERR_FAIL(); // Can't call.
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 11:44:07 +00:00
|
|
|
MethodBindVarArgBase(
|
2022-12-07 13:11:44 +00:00
|
|
|
R (T::*p_method)(const Variant **, GDExtensionInt, GDExtensionCallError &),
|
2022-03-29 11:44:07 +00:00
|
|
|
const MethodInfo &p_method_info,
|
|
|
|
bool p_return_nil_is_variant) :
|
2022-09-02 07:41:24 +00:00
|
|
|
method(p_method) {
|
2022-05-04 11:27:08 +00:00
|
|
|
set_vararg(true);
|
|
|
|
set_const(true);
|
2022-09-02 07:41:24 +00:00
|
|
|
set_argument_count(p_method_info.arguments.size());
|
|
|
|
if (p_method_info.arguments.size()) {
|
2022-10-22 17:42:48 +00:00
|
|
|
arguments = p_method_info.arguments;
|
|
|
|
|
|
|
|
std::vector<StringName> names;
|
2022-09-02 07:41:24 +00:00
|
|
|
names.reserve(p_method_info.arguments.size());
|
2023-01-19 12:40:18 +00:00
|
|
|
for (size_t i = 0; i < p_method_info.arguments.size(); i++) {
|
2022-10-22 17:42:48 +00:00
|
|
|
names.push_back(p_method_info.arguments[i].name);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
set_argument_names(names);
|
|
|
|
}
|
|
|
|
|
2022-09-02 07:41:24 +00:00
|
|
|
generate_argument_types((int)p_method_info.arguments.size());
|
2022-03-29 11:44:07 +00:00
|
|
|
set_return(should_returns);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
~MethodBindVarArgBase() {}
|
2022-09-02 07:41:24 +00:00
|
|
|
|
2022-03-29 11:44:07 +00:00
|
|
|
private:
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo _gen_return_type_info() const {
|
2022-03-29 11:44:07 +00:00
|
|
|
return reinterpret_cast<const Derived *>(this)->_gen_return_type_info_impl();
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
2022-03-29 11:44:07 +00:00
|
|
|
};
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T>
|
2022-03-29 11:44:07 +00:00
|
|
|
class MethodBindVarArgT : public MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false> {
|
|
|
|
friend class MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>;
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-03-29 11:44:07 +00:00
|
|
|
public:
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2022-03-29 11:44:07 +00:00
|
|
|
(static_cast<T *>(p_instance)->*MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>::method)((const Variant **)p_args, p_argument_count, r_error);
|
|
|
|
return {};
|
|
|
|
}
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-03-29 11:44:07 +00:00
|
|
|
MethodBindVarArgT(
|
2022-12-07 13:11:44 +00:00
|
|
|
void (T::*p_method)(const Variant **, GDExtensionInt, GDExtensionCallError &),
|
2022-03-29 11:44:07 +00:00
|
|
|
const MethodInfo &p_method_info,
|
|
|
|
bool p_return_nil_is_variant) :
|
|
|
|
MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>(p_method, p_method_info, p_return_nil_is_variant) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo _gen_return_type_info_impl() const {
|
2022-03-29 11:44:07 +00:00
|
|
|
return {};
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T>
|
2022-12-07 13:11:44 +00:00
|
|
|
MethodBind *create_vararg_method_bind(void (T::*p_method)(const Variant **, GDExtensionInt, GDExtensionCallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) {
|
2022-03-29 11:44:07 +00:00
|
|
|
MethodBind *a = memnew((MethodBindVarArgT<T>)(p_method, p_info, p_return_nil_is_variant));
|
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R>
|
2022-03-29 11:44:07 +00:00
|
|
|
class MethodBindVarArgTR : public MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true> {
|
|
|
|
friend class MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>;
|
|
|
|
|
|
|
|
public:
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2022-03-29 11:44:07 +00:00
|
|
|
return (static_cast<T *>(p_instance)->*MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>::method)((const Variant **)p_args, p_argument_count, r_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindVarArgTR(
|
2022-12-07 13:11:44 +00:00
|
|
|
R (T::*p_method)(const Variant **, GDExtensionInt, GDExtensionCallError &),
|
2022-03-29 11:44:07 +00:00
|
|
|
const MethodInfo &p_info,
|
|
|
|
bool p_return_nil_is_variant) :
|
|
|
|
MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>(p_method, p_info, p_return_nil_is_variant) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo _gen_return_type_info_impl() const {
|
2022-03-29 11:44:07 +00:00
|
|
|
return GetTypeInfo<R>::get_class_info();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R>
|
2022-12-07 13:11:44 +00:00
|
|
|
MethodBind *create_vararg_method_bind(R (T::*p_method)(const Variant **, GDExtensionInt, GDExtensionCallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) {
|
2022-03-29 11:44:07 +00:00
|
|
|
MethodBind *a = memnew((MethodBindVarArgTR<T, R>)(p_method, p_info, p_return_nil_is_variant));
|
2021-08-18 14:03:52 +00:00
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TYPED_METHOD_BIND
|
2023-02-16 15:38:38 +00:00
|
|
|
class _gde_UnexistingClass;
|
|
|
|
#define MB_T _gde_UnexistingClass
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
|
|
|
#define MB_T T
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// No return, not const.
|
|
|
|
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
class MethodBindT : public MethodBind {
|
|
|
|
void (MB_T::*method)(P...);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDEXTENSION_VARIANT_TYPE_NIL;
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
|
|
|
PropertyInfo pi;
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
} else {
|
2022-10-22 17:42:48 +00:00
|
|
|
pi = PropertyInfo();
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
return call_get_argument_metadata<P...>(p_argument);
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-11-12 10:03:29 +00:00
|
|
|
call_with_variant_args_dv(static_cast<T *>(p_instance), method, p_args, (int)p_argument_count, r_error, get_default_arguments());
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
|
|
|
call_with_variant_args_dv(reinterpret_cast<MB_T *>(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments());
|
|
|
|
#endif
|
|
|
|
return Variant();
|
|
|
|
}
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-08-19 23:03:11 +00:00
|
|
|
call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args, nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2021-08-19 23:03:11 +00:00
|
|
|
call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindT(void (MB_T::*p_method)(P...)) {
|
|
|
|
method = p_method;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
MethodBind *create_method_bind(void (T::*p_method)(P...)) {
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
MethodBind *a = memnew((MethodBindT<T, P...>)(p_method));
|
|
|
|
#else
|
|
|
|
MethodBind *a = memnew((MethodBindT<P...>)(reinterpret_cast<void (MB_T::*)(P...)>(p_method)));
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No return, const.
|
|
|
|
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
class MethodBindTC : public MethodBind {
|
|
|
|
void (MB_T::*method)(P...) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDEXTENSION_VARIANT_TYPE_NIL;
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
|
|
|
PropertyInfo pi;
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
} else {
|
2022-10-22 17:42:48 +00:00
|
|
|
pi = PropertyInfo();
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
return call_get_argument_metadata<P...>(p_argument);
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-11-12 10:03:29 +00:00
|
|
|
call_with_variant_argsc_dv(static_cast<T *>(p_instance), method, p_args, (int)p_argument_count, r_error, get_default_arguments());
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
|
|
|
call_with_variant_argsc_dv(reinterpret_cast<MB_T *>(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments());
|
|
|
|
#endif
|
|
|
|
return Variant();
|
|
|
|
}
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-08-19 23:03:11 +00:00
|
|
|
call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args, nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2021-08-19 23:03:11 +00:00
|
|
|
call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindTC(void (MB_T::*p_method)(P...) const) {
|
|
|
|
method = p_method;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
2024-01-25 14:54:58 +00:00
|
|
|
set_const(true);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
MethodBind *create_method_bind(void (T::*p_method)(P...) const) {
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
MethodBind *a = memnew((MethodBindTC<T, P...>)(p_method));
|
|
|
|
#else
|
|
|
|
MethodBind *a = memnew((MethodBindTC<P...>)(reinterpret_cast<void (MB_T::*)(P...) const>(p_method)));
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return, not const.
|
|
|
|
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
class MethodBindTR : public MethodBind {
|
|
|
|
R(MB_T::*method)
|
|
|
|
(P...);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDExtensionVariantType(GetTypeInfo<R>::VARIANT_TYPE);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo pi;
|
2021-08-18 14:03:52 +00:00
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
return pi;
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::get_class_info();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_argument >= 0) {
|
|
|
|
return call_get_argument_metadata<P...>(p_argument);
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::METADATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
Variant ret;
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-11-12 10:03:29 +00:00
|
|
|
call_with_variant_args_ret_dv(static_cast<T *>(p_instance), method, p_args, (int)p_argument_count, ret, r_error, get_default_arguments());
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
|
|
|
call_with_variant_args_ret_dv((MB_T *)p_instance, method, p_args, p_argument_count, ret, r_error, get_default_arguments());
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
call_with_ptr_args<T, R, P...>(static_cast<T *>(p_instance), method, p_args, r_ret);
|
|
|
|
#else
|
|
|
|
call_with_ptr_args<MB_T, R, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, r_ret);
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindTR(R (MB_T::*p_method)(P...)) {
|
|
|
|
method = p_method;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
|
|
|
set_return(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
MethodBind *create_method_bind(R (T::*p_method)(P...)) {
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
MethodBind *a = memnew((MethodBindTR<T, R, P...>)(p_method));
|
|
|
|
#else
|
|
|
|
MethodBind *a = memnew((MethodBindTR<R, P...>)(reinterpret_cast<R (MB_T::*)(P...)>(p_method)));
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return, const.
|
|
|
|
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
class MethodBindTRC : public MethodBind {
|
|
|
|
R(MB_T::*method)
|
|
|
|
(P...) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDExtensionVariantType(GetTypeInfo<R>::VARIANT_TYPE);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo pi;
|
2021-08-18 14:03:52 +00:00
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
return pi;
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::get_class_info();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
if (p_argument >= 0) {
|
|
|
|
return call_get_argument_metadata<P...>(p_argument);
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::METADATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionCallError &r_error) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
Variant ret;
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
2021-11-12 10:03:29 +00:00
|
|
|
call_with_variant_args_retc_dv(static_cast<T *>(p_instance), method, p_args, (int)p_argument_count, ret, r_error, get_default_arguments());
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
|
|
|
call_with_variant_args_retc_dv((MB_T *)p_instance, method, p_args, p_argument_count, ret, r_error, get_default_arguments());
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2021-08-18 14:03:52 +00:00
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
call_with_ptr_args<T, R, P...>(static_cast<T *>(p_instance), method, p_args, r_ret);
|
|
|
|
#else
|
|
|
|
call_with_ptr_args<MB_T, R, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, r_ret);
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindTRC(R (MB_T::*p_method)(P...) const) {
|
|
|
|
method = p_method;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
|
|
|
set_return(true);
|
2024-01-25 14:54:58 +00:00
|
|
|
set_const(true);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T, typename R, typename... P>
|
2021-08-18 14:03:52 +00:00
|
|
|
MethodBind *create_method_bind(R (T::*p_method)(P...) const) {
|
|
|
|
#ifdef TYPED_METHOD_BIND
|
|
|
|
MethodBind *a = memnew((MethodBindTRC<T, R, P...>)(p_method));
|
|
|
|
#else
|
|
|
|
MethodBind *a = memnew((MethodBindTRC<R, P...>)(reinterpret_cast<R (MB_T::*)(P...) const>(p_method)));
|
|
|
|
#endif // TYPED_METHOD_BIND
|
|
|
|
a->set_instance_class(T::get_class_static());
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2022-05-04 11:27:08 +00:00
|
|
|
// STATIC BINDS
|
|
|
|
|
|
|
|
// no return
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... P>
|
2022-05-04 11:27:08 +00:00
|
|
|
class MethodBindTS : public MethodBind {
|
|
|
|
void (*function)(P...);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDEXTENSION_VARIANT_TYPE_NIL;
|
2022-05-04 11:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
|
|
|
PropertyInfo pi;
|
2022-06-28 18:36:47 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
} else {
|
2022-10-22 17:42:48 +00:00
|
|
|
pi = PropertyInfo();
|
2022-06-28 18:36:47 +00:00
|
|
|
}
|
2022-05-04 11:27:08 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_arg) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
return call_get_argument_metadata<P...>(p_arg);
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_object, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_arg_count, GDExtensionCallError &r_error) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
(void)p_object; // unused
|
|
|
|
call_with_variant_args_static_dv(function, p_args, p_arg_count, r_error, get_default_arguments());
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_object, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
(void)p_object;
|
|
|
|
(void)r_ret;
|
|
|
|
call_with_ptr_args_static_method(function, p_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindTS(void (*p_function)(P...)) {
|
|
|
|
function = p_function;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
|
|
|
set_static(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... P>
|
2022-05-04 11:27:08 +00:00
|
|
|
MethodBind *create_static_method_bind(void (*p_method)(P...)) {
|
|
|
|
MethodBind *a = memnew((MethodBindTS<P...>)(p_method));
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... P>
|
2022-05-04 11:27:08 +00:00
|
|
|
class MethodBindTRS : public MethodBind {
|
|
|
|
R(*function)
|
|
|
|
(P...);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// GCC raises warnings in the case P = {} as the comparison is always false...
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wlogical-op"
|
|
|
|
#endif
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionVariantType gen_argument_type(int p_arg) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
|
|
|
return call_get_argument_type<P...>(p_arg);
|
|
|
|
} else {
|
2022-12-07 13:11:44 +00:00
|
|
|
return GDExtensionVariantType(GetTypeInfo<R>::VARIANT_TYPE);
|
2022-05-04 11:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:42:48 +00:00
|
|
|
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
|
2022-10-22 17:42:48 +00:00
|
|
|
PropertyInfo pi;
|
2022-05-04 11:27:08 +00:00
|
|
|
call_get_argument_type_info<P...>(p_arg, pi);
|
|
|
|
return pi;
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::get_class_info();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2022-12-07 13:11:44 +00:00
|
|
|
virtual GDExtensionClassMethodArgumentMetadata get_argument_metadata(int p_arg) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
if (p_arg >= 0) {
|
|
|
|
return call_get_argument_metadata<P...>(p_arg);
|
|
|
|
} else {
|
|
|
|
return GetTypeInfo<R>::METADATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual Variant call(GDExtensionClassInstancePtr p_object, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_arg_count, GDExtensionCallError &r_error) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
Variant ret;
|
|
|
|
call_with_variant_args_static_ret_dv(function, p_args, p_arg_count, ret, r_error, get_default_arguments());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:47:42 +00:00
|
|
|
virtual void ptrcall(GDExtensionClassInstancePtr p_object, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) const {
|
2022-05-04 11:27:08 +00:00
|
|
|
(void)p_object;
|
|
|
|
call_with_ptr_args_static_method_ret(function, p_args, r_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodBindTRS(R (*p_function)(P...)) {
|
|
|
|
function = p_function;
|
|
|
|
generate_argument_types(sizeof...(P));
|
|
|
|
set_argument_count(sizeof...(P));
|
|
|
|
set_static(true);
|
|
|
|
set_return(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... P>
|
2022-05-04 11:27:08 +00:00
|
|
|
MethodBind *create_static_method_bind(R (*p_method)(P...)) {
|
|
|
|
MethodBind *a = memnew((MethodBindTRS<R, P...>)(p_method));
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
} // namespace godot
|
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#endif // GODOT_METHOD_BIND_HPP
|