summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2021-08-19 14:47:56 -0300
committerBastiaan Olij <mux213@gmail.com>2021-09-27 23:08:08 +1000
commit8bcf32a61946620017f61568f4aa10070db4bd4e (patch)
treea8b115439d994eee49ab03ceeccaa5c9912ca596 /include/godot_cpp
parente4ed48976a962b67e9585cc2d20d11f115ef7949 (diff)
downloadredot-cpp-8bcf32a61946620017f61568f4aa10070db4bd4e.tar.gz
Fix issues with method calls
Diffstat (limited to 'include/godot_cpp')
-rw-r--r--include/godot_cpp/core/binder_common.hpp8
-rw-r--r--include/godot_cpp/core/type_info.hpp48
-rw-r--r--include/godot_cpp/variant/variant.hpp10
3 files changed, 55 insertions, 11 deletions
diff --git a/include/godot_cpp/core/binder_common.hpp b/include/godot_cpp/core/binder_common.hpp
index c1827fa..a2ce8f5 100644
--- a/include/godot_cpp/core/binder_common.hpp
+++ b/include/godot_cpp/core/binder_common.hpp
@@ -259,7 +259,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const G
std::array<const Variant *, sizeof...(P)> argsp;
for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
if (i < p_argcount) {
- args[i] = p_args[i];
+ args[i] = Variant(p_args[i]);
} else {
args[i] = default_values[i - p_argcount + (dvs - missing)];
}
@@ -294,7 +294,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const,
std::array<const Variant *, sizeof...(P)> argsp;
for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
if (i < p_argcount) {
- args[i] = p_args[i];
+ args[i] = Variant(p_args[i]);
} else {
args[i] = default_values[i - p_argcount + (dvs - missing)];
}
@@ -329,7 +329,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const
std::array<const Variant *, sizeof...(P)> argsp;
for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
if (i < p_argcount) {
- args[i] = p_args[i];
+ args[i] = Variant(p_args[i]);
} else {
args[i] = default_values[i - p_argcount + (dvs - missing)];
}
@@ -364,7 +364,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const,
std::array<const Variant *, sizeof...(P)> argsp;
for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
if (i < p_argcount) {
- args[i] = p_args[i];
+ args[i] = Variant(p_args[i]);
} else {
args[i] = default_values[i - p_argcount + (dvs - missing)];
}
diff --git a/include/godot_cpp/core/type_info.hpp b/include/godot_cpp/core/type_info.hpp
index d7a7473..94ffb3b 100644
--- a/include/godot_cpp/core/type_info.hpp
+++ b/include/godot_cpp/core/type_info.hpp
@@ -38,6 +38,36 @@
namespace godot {
+template <bool C, typename T = void>
+struct EnableIf {
+ typedef T type;
+};
+
+template <typename T>
+struct EnableIf<false, T> {
+};
+
+template <typename, typename>
+struct TypesAreSame {
+ static bool const value = false;
+};
+
+template <typename A>
+struct TypesAreSame<A, A> {
+ static bool const value = true;
+};
+
+template <typename B, typename D>
+struct TypeInherits {
+ static D *get_d();
+
+ static char (&test(B *))[1];
+ static char (&test(...))[2];
+
+ static bool const value = sizeof(test(get_d())) == sizeof(char) &&
+ !TypesAreSame<B volatile const, void volatile const>::value;
+};
+
// If the compiler fails because it's trying to instantiate the primary 'GetTypeInfo' template
// instead of one of the specializations, it's most likely because the type 'T' is not supported.
// If 'T' is a class that inherits 'Object', make sure it can see the actual class declaration
@@ -147,6 +177,24 @@ struct GetTypeInfo<const Variant &> {
}
};
+template <typename T>
+struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
+ static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
+ static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
+ static inline PropertyInfo get_class_info() {
+ return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ }
+};
+
+template <typename T>
+struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
+ static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
+ static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
+ static inline PropertyInfo get_class_info() {
+ return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
+ }
+};
+
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp
index f94f907..32536c8 100644
--- a/include/godot_cpp/variant/variant.hpp
+++ b/include/godot_cpp/variant/variant.hpp
@@ -44,7 +44,8 @@ namespace godot {
class Variant {
uint8_t opaque[GODOT_CPP_VARIANT_SIZE]{ 0 };
- GDNativeVariantPtr ptr = const_cast<uint8_t (*)[GODOT_CPP_VARIANT_SIZE]>(&opaque);
+
+ _FORCE_INLINE_ GDNativeVariantPtr ptr() const { return const_cast<uint8_t(*)[GODOT_CPP_VARIANT_SIZE]>(&opaque); }
friend class GDExtensionBinding;
friend class MethodBind;
@@ -141,7 +142,7 @@ public:
Variant();
Variant(std::nullptr_t n) :
Variant() {}
- Variant(const GDNativeVariantPtr native_ptr);
+ explicit Variant(const GDNativeVariantPtr native_ptr);
Variant(const Variant &other);
Variant(Variant &&other);
Variant(bool v);
@@ -235,17 +236,12 @@ public:
operator PackedVector3Array() const;
operator PackedColorArray() const;
- operator const GDNativeVariantPtr() const;
- operator GDNativeVariantPtr();
-
Variant &operator=(const Variant &other);
Variant &operator=(Variant &&other);
bool operator==(const Variant &other) const;
bool operator!=(const Variant &other) const;
bool operator<(const Variant &other) const;
- void operator=(const GDNativeVariantPtr other_ptr);
-
void call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDNativeCallError &r_error);
template <class... Args>