summaryrefslogtreecommitdiff
path: root/modules/gdnative/gdnative/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/gdnative/variant.cpp')
-rw-r--r--modules/gdnative/gdnative/variant.cpp133
1 files changed, 127 insertions, 6 deletions
diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp
index f0fc44ae8a..dac4feb0e5 100644
--- a/modules/gdnative/gdnative/variant.cpp
+++ b/modules/gdnative/gdnative/variant.cpp
@@ -37,6 +37,8 @@
extern "C" {
#endif
+static_assert(sizeof(godot_variant) == sizeof(Variant), "Variant size mismatch");
+
// Workaround GCC ICE on armv7hl which was affected GCC 6.0 up to 8.0 (GH-16100).
// It was fixed upstream in 8.1, and a fix was backported to 7.4.
// This can be removed once no supported distro ships with versions older than 7.4.
@@ -97,24 +99,48 @@ void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p
memnew_placement_custom(dest, Variant, Variant(*s));
}
+void GDAPI godot_variant_new_string_name(godot_variant *r_dest, const godot_string_name *p_s) {
+ Variant *dest = (Variant *)r_dest;
+ StringName *s = (StringName *)p_s;
+ memnew_placement_custom(dest, Variant, Variant(*s));
+}
+
void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2) {
Variant *dest = (Variant *)r_dest;
Vector2 *v2 = (Vector2 *)p_v2;
memnew_placement_custom(dest, Variant, Variant(*v2));
}
+void GDAPI godot_variant_new_vector2i(godot_variant *r_dest, const godot_vector2i *p_v2) {
+ Variant *dest = (Variant *)r_dest;
+ Vector2i *v2 = (Vector2i *)p_v2;
+ memnew_placement_custom(dest, Variant, Variant(*v2));
+}
+
void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2) {
Variant *dest = (Variant *)r_dest;
Rect2 *rect2 = (Rect2 *)p_rect2;
memnew_placement_custom(dest, Variant, Variant(*rect2));
}
+void GDAPI godot_variant_new_rect2i(godot_variant *r_dest, const godot_rect2i *p_rect2) {
+ Variant *dest = (Variant *)r_dest;
+ Rect2i *rect2 = (Rect2i *)p_rect2;
+ memnew_placement_custom(dest, Variant, Variant(*rect2));
+}
+
void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3) {
Variant *dest = (Variant *)r_dest;
Vector3 *v3 = (Vector3 *)p_v3;
memnew_placement_custom(dest, Variant, Variant(*v3));
}
+void GDAPI godot_variant_new_vector3i(godot_variant *r_dest, const godot_vector3i *p_v3) {
+ Variant *dest = (Variant *)r_dest;
+ Vector3i *v3 = (Vector3i *)p_v3;
+ memnew_placement_custom(dest, Variant, Variant(*v3));
+}
+
void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d) {
Variant *dest = (Variant *)r_dest;
Transform2D *t2d = (Transform2D *)p_t2d;
@@ -169,6 +195,18 @@ void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid)
memnew_placement_custom(dest, Variant, Variant(*rid));
}
+void GDAPI godot_variant_new_callable(godot_variant *r_dest, const godot_callable *p_cb) {
+ Variant *dest = (Variant *)r_dest;
+ Callable *cb = (Callable *)p_cb;
+ memnew_placement_custom(dest, Variant, Variant(*cb));
+}
+
+void GDAPI godot_variant_new_signal(godot_variant *r_dest, const godot_signal *p_signal) {
+ Variant *dest = (Variant *)r_dest;
+ Signal *signal = (Signal *)p_signal;
+ memnew_placement_custom(dest, Variant, Variant(*signal));
+}
+
void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) {
Variant *dest = (Variant *)r_dest;
Object *obj = (Object *)p_obj;
@@ -207,18 +245,30 @@ void GDAPI godot_variant_new_packed_byte_array(godot_variant *r_dest, const godo
memnew_placement_custom(dest, Variant, Variant(*pba));
}
-void GDAPI godot_variant_new_packed_int_array(godot_variant *r_dest, const godot_packed_int_array *p_pia) {
+void GDAPI godot_variant_new_packed_int32_array(godot_variant *r_dest, const godot_packed_int32_array *p_pia) {
Variant *dest = (Variant *)r_dest;
PackedInt32Array *pia = (PackedInt32Array *)p_pia;
memnew_placement_custom(dest, Variant, Variant(*pia));
}
-void GDAPI godot_variant_new_packed_real_array(godot_variant *r_dest, const godot_packed_real_array *p_pra) {
+void GDAPI godot_variant_new_packed_int64_array(godot_variant *r_dest, const godot_packed_int64_array *p_pia) {
+ Variant *dest = (Variant *)r_dest;
+ PackedInt64Array *pia = (PackedInt64Array *)p_pia;
+ memnew_placement_custom(dest, Variant, Variant(*pia));
+}
+
+void GDAPI godot_variant_new_packed_float32_array(godot_variant *r_dest, const godot_packed_float32_array *p_pra) {
Variant *dest = (Variant *)r_dest;
PackedFloat32Array *pra = (PackedFloat32Array *)p_pra;
memnew_placement_custom(dest, Variant, Variant(*pra));
}
+void GDAPI godot_variant_new_packed_float64_array(godot_variant *r_dest, const godot_packed_float64_array *p_pra) {
+ Variant *dest = (Variant *)r_dest;
+ PackedFloat64Array *pra = (PackedFloat64Array *)p_pra;
+ memnew_placement_custom(dest, Variant, Variant(*pra));
+}
+
void GDAPI godot_variant_new_packed_string_array(godot_variant *r_dest, const godot_packed_string_array *p_psa) {
Variant *dest = (Variant *)r_dest;
PackedStringArray *psa = (PackedStringArray *)p_psa;
@@ -271,6 +321,14 @@ godot_string GDAPI godot_variant_as_string(const godot_variant *p_self) {
return raw_dest;
}
+godot_string_name GDAPI godot_variant_as_string_name(const godot_variant *p_self) {
+ godot_string_name raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ StringName *dest = (StringName *)&raw_dest;
+ memnew_placement(dest, StringName(self->operator StringName())); // operator = is overloaded by StringName
+ return raw_dest;
+}
+
godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self) {
godot_vector2 raw_dest;
const Variant *self = (const Variant *)p_self;
@@ -279,6 +337,14 @@ godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self) {
return raw_dest;
}
+godot_vector2i GDAPI godot_variant_as_vector2i(const godot_variant *p_self) {
+ godot_vector2i raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ Vector2i *dest = (Vector2i *)&raw_dest;
+ *dest = *self;
+ return raw_dest;
+}
+
godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self) {
godot_rect2 raw_dest;
const Variant *self = (const Variant *)p_self;
@@ -287,6 +353,14 @@ godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self) {
return raw_dest;
}
+godot_rect2i GDAPI godot_variant_as_rect2i(const godot_variant *p_self) {
+ godot_rect2i raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ Rect2i *dest = (Rect2i *)&raw_dest;
+ *dest = *self;
+ return raw_dest;
+}
+
godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self) {
godot_vector3 raw_dest;
const Variant *self = (const Variant *)p_self;
@@ -295,6 +369,14 @@ godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self) {
return raw_dest;
}
+godot_vector3i GDAPI godot_variant_as_vector3i(const godot_variant *p_self) {
+ godot_vector3i raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ Vector3i *dest = (Vector3i *)&raw_dest;
+ *dest = *self;
+ return raw_dest;
+}
+
godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self) {
godot_transform2d raw_dest;
const Variant *self = (const Variant *)p_self;
@@ -367,6 +449,22 @@ godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self) {
return raw_dest;
}
+godot_callable GDAPI godot_variant_as_callable(const godot_variant *p_self) {
+ godot_callable raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ Callable *dest = (Callable *)&raw_dest;
+ *dest = *self;
+ return raw_dest;
+}
+
+godot_signal GDAPI godot_variant_as_signal(const godot_variant *p_self) {
+ godot_signal raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ Signal *dest = (Signal *)&raw_dest;
+ *dest = *self;
+ return raw_dest;
+}
+
godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self) {
const Variant *self = (const Variant *)p_self;
Object *dest;
@@ -399,8 +497,8 @@ godot_packed_byte_array GDAPI godot_variant_as_packed_byte_array(const godot_var
return raw_dest;
}
-godot_packed_int_array GDAPI godot_variant_as_packed_int_array(const godot_variant *p_self) {
- godot_packed_int_array raw_dest;
+godot_packed_int32_array GDAPI godot_variant_as_packed_int32_array(const godot_variant *p_self) {
+ godot_packed_int32_array raw_dest;
const Variant *self = (const Variant *)p_self;
PackedInt32Array *dest = (PackedInt32Array *)&raw_dest;
memnew_placement(dest, PackedInt32Array(self->operator PackedInt32Array())); // operator = is overloaded by PackedInt32Array
@@ -408,8 +506,17 @@ godot_packed_int_array GDAPI godot_variant_as_packed_int_array(const godot_varia
return raw_dest;
}
-godot_packed_real_array GDAPI godot_variant_as_packed_real_array(const godot_variant *p_self) {
- godot_packed_real_array raw_dest;
+godot_packed_int64_array GDAPI godot_variant_as_packed_int64_array(const godot_variant *p_self) {
+ godot_packed_int64_array raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ PackedInt64Array *dest = (PackedInt64Array *)&raw_dest;
+ memnew_placement(dest, PackedInt64Array(self->operator PackedInt64Array())); // operator = is overloaded by PackedInt64Array
+ *dest = *self;
+ return raw_dest;
+}
+
+godot_packed_float32_array GDAPI godot_variant_as_packed_float32_array(const godot_variant *p_self) {
+ godot_packed_float32_array raw_dest;
const Variant *self = (const Variant *)p_self;
PackedFloat32Array *dest = (PackedFloat32Array *)&raw_dest;
memnew_placement(dest, PackedFloat32Array(self->operator PackedFloat32Array())); // operator = is overloaded by PackedFloat32Array
@@ -417,6 +524,15 @@ godot_packed_real_array GDAPI godot_variant_as_packed_real_array(const godot_var
return raw_dest;
}
+godot_packed_float64_array GDAPI godot_variant_as_packed_float64_array(const godot_variant *p_self) {
+ godot_packed_float64_array raw_dest;
+ const Variant *self = (const Variant *)p_self;
+ PackedFloat64Array *dest = (PackedFloat64Array *)&raw_dest;
+ memnew_placement(dest, PackedFloat64Array(self->operator PackedFloat64Array())); // operator = is overloaded by PackedFloat64Array
+ *dest = *self;
+ return raw_dest;
+}
+
godot_packed_string_array GDAPI godot_variant_as_packed_string_array(const godot_variant *p_self) {
godot_packed_string_array raw_dest;
const Variant *self = (const Variant *)p_self;
@@ -487,6 +603,11 @@ godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const
return self->operator<(*other);
}
+uint32_t GDAPI godot_variant_hash(const godot_variant *p_self) {
+ const Variant *self = (const Variant *)p_self;
+ return self->hash();
+}
+
godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other) {
const Variant *self = (const Variant *)p_self;
const Variant *other = (const Variant *)p_other;