diff options
Diffstat (limited to 'modules/gdnative/gdnative/variant.cpp')
-rw-r--r-- | modules/gdnative/gdnative/variant.cpp | 707 |
1 files changed, 621 insertions, 86 deletions
diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index 7ee5fe59e2..79f5a536e5 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -55,16 +55,11 @@ static_assert(sizeof(godot_variant) == sizeof(Variant), "Variant size mismatch") #pragma GCC pop_options #endif -// Constructors - -godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_self) { - const Variant *self = (const Variant *)p_self; - return (godot_variant_type)self->get_type(); -} +// Memory void GDAPI godot_variant_new_copy(godot_variant *p_dest, const godot_variant *p_src) { Variant *dest = (Variant *)p_dest; - Variant *src = (Variant *)p_src; + const Variant *src = (const Variant *)p_src; memnew_placement(dest, Variant(*src)); } @@ -78,139 +73,134 @@ void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b) { memnew_placement_custom(dest, Variant, Variant(p_b)); } -void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i) { +void GDAPI godot_variant_new_int(godot_variant *r_dest, const godot_int p_i) { Variant *dest = (Variant *)r_dest; memnew_placement_custom(dest, Variant, Variant(p_i)); } -void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i) { - Variant *dest = (Variant *)r_dest; - memnew_placement_custom(dest, Variant, Variant(p_i)); -} - -void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r) { +void GDAPI godot_variant_new_float(godot_variant *r_dest, const godot_float p_r) { Variant *dest = (Variant *)r_dest; memnew_placement_custom(dest, Variant, Variant(p_r)); } void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s) { Variant *dest = (Variant *)r_dest; - String *s = (String *)p_s; + const String *s = (const String *)p_s; 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; + const StringName *s = (const 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; + const Vector2 *v2 = (const 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; + const Vector2i *v2 = (const 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; + const Rect2 *rect2 = (const 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; + const Rect2i *rect2 = (const 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; + const Vector3 *v3 = (const 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; + const Vector3i *v3 = (const 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; + const Transform2D *t2d = (const Transform2D *)p_t2d; memnew_placement_custom(dest, Variant, Variant(*t2d)); } void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane) { Variant *dest = (Variant *)r_dest; - Plane *plane = (Plane *)p_plane; + const Plane *plane = (const Plane *)p_plane; memnew_placement_custom(dest, Variant, Variant(*plane)); } void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat) { Variant *dest = (Variant *)r_dest; - Quat *quat = (Quat *)p_quat; + const Quat *quat = (const Quat *)p_quat; memnew_placement_custom(dest, Variant, Variant(*quat)); } void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb) { Variant *dest = (Variant *)r_dest; - AABB *aabb = (AABB *)p_aabb; + const AABB *aabb = (const AABB *)p_aabb; memnew_placement_custom(dest, Variant, Variant(*aabb)); } void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis) { Variant *dest = (Variant *)r_dest; - Basis *basis = (Basis *)p_basis; + const Basis *basis = (const Basis *)p_basis; memnew_placement_custom(dest, Variant, Variant(*basis)); } void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans) { Variant *dest = (Variant *)r_dest; - Transform *trans = (Transform *)p_trans; + const Transform *trans = (const Transform *)p_trans; memnew_placement_custom(dest, Variant, Variant(*trans)); } void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color) { Variant *dest = (Variant *)r_dest; - Color *color = (Color *)p_color; + const Color *color = (const Color *)p_color; memnew_placement_custom(dest, Variant, Variant(*color)); } void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np) { Variant *dest = (Variant *)r_dest; - NodePath *np = (NodePath *)p_np; + const NodePath *np = (const NodePath *)p_np; memnew_placement_custom(dest, Variant, Variant(*np)); } void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid) { Variant *dest = (Variant *)r_dest; - RID *rid = (RID *)p_rid; + const RID *rid = (const 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; + const Callable *cb = (const 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; + const Signal *signal = (const 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; - Reference *reference = Object::cast_to<Reference>(obj); + const Object *obj = (const Object *)p_obj; + const Reference *reference = Object::cast_to<Reference>(obj); REF ref; if (reference) { ref = REF(reference); @@ -229,67 +219,67 @@ void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) { Variant *dest = (Variant *)r_dest; - Dictionary *dict = (Dictionary *)p_dict; + const Dictionary *dict = (const Dictionary *)p_dict; memnew_placement_custom(dest, Variant, Variant(*dict)); } void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr) { Variant *dest = (Variant *)r_dest; - Array *arr = (Array *)p_arr; + const Array *arr = (const Array *)p_arr; memnew_placement_custom(dest, Variant, Variant(*arr)); } void GDAPI godot_variant_new_packed_byte_array(godot_variant *r_dest, const godot_packed_byte_array *p_pba) { Variant *dest = (Variant *)r_dest; - PackedByteArray *pba = (PackedByteArray *)p_pba; + const PackedByteArray *pba = (const PackedByteArray *)p_pba; memnew_placement_custom(dest, Variant, Variant(*pba)); } 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; + const PackedInt32Array *pia = (const PackedInt32Array *)p_pia; memnew_placement_custom(dest, Variant, Variant(*pia)); } 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; + const PackedInt64Array *pia = (const 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; + const PackedFloat32Array *pra = (const 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; + const PackedFloat64Array *pra = (const 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; + const PackedStringArray *psa = (const PackedStringArray *)p_psa; memnew_placement_custom(dest, Variant, Variant(*psa)); } void GDAPI godot_variant_new_packed_vector2_array(godot_variant *r_dest, const godot_packed_vector2_array *p_pv2a) { Variant *dest = (Variant *)r_dest; - PackedVector2Array *pv2a = (PackedVector2Array *)p_pv2a; + const PackedVector2Array *pv2a = (const PackedVector2Array *)p_pv2a; memnew_placement_custom(dest, Variant, Variant(*pv2a)); } void GDAPI godot_variant_new_packed_vector3_array(godot_variant *r_dest, const godot_packed_vector3_array *p_pv3a) { Variant *dest = (Variant *)r_dest; - PackedVector3Array *pv3a = (PackedVector3Array *)p_pv3a; + const PackedVector3Array *pv3a = (const PackedVector3Array *)p_pv3a; memnew_placement_custom(dest, Variant, Variant(*pv3a)); } void GDAPI godot_variant_new_packed_color_array(godot_variant *r_dest, const godot_packed_color_array *p_pca) { Variant *dest = (Variant *)r_dest; - PackedColorArray *pca = (PackedColorArray *)p_pca; + const PackedColorArray *pca = (const PackedColorArray *)p_pca; memnew_placement_custom(dest, Variant, Variant(*pca)); } @@ -298,17 +288,12 @@ godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self) { return self->operator bool(); } -uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self) { - const Variant *self = (const Variant *)p_self; - return self->operator uint64_t(); -} - -int64_t GDAPI godot_variant_as_int(const godot_variant *p_self) { +godot_int GDAPI godot_variant_as_int(const godot_variant *p_self) { const Variant *self = (const Variant *)p_self; return self->operator int64_t(); } -double GDAPI godot_variant_as_real(const godot_variant *p_self) { +godot_float GDAPI godot_variant_as_float(const godot_variant *p_self) { const Variant *self = (const Variant *)p_self; return self->operator double(); } @@ -569,47 +554,137 @@ godot_packed_color_array GDAPI godot_variant_as_packed_color_array(const godot_v return raw_dest; } -godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error) { +void GDAPI godot_variant_destroy(godot_variant *p_self) { Variant *self = (Variant *)p_self; - String *method = (String *)p_method; + self->~Variant(); +} + +// Dynamic interaction. + +void GDAPI godot_variant_call(godot_variant *p_self, const godot_string_name *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant *r_return, godot_variant_call_error *r_error) { + Variant *self = (Variant *)p_self; + const StringName *method = (const StringName *)p_method; const Variant **args = (const Variant **)p_args; - godot_variant raw_dest; - Variant *dest = (Variant *)&raw_dest; - Callable::CallError error; Variant ret; + Callable::CallError error; self->call(*method, args, p_argcount, ret, error); - memnew_placement_custom(dest, Variant, Variant(ret)); + memnew_placement_custom(r_return, Variant, Variant(ret)); + if (r_error) { r_error->error = (godot_variant_call_error_error)error.error; r_error->argument = error.argument; r_error->expected = (godot_variant_type)error.expected; } - return raw_dest; } -godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method) { +void GDAPI godot_variant_evaluate(godot_variant_operator p_op, const godot_variant *p_a, const godot_variant *p_b, godot_variant *r_return, bool *r_valid) { + Variant::Operator op = (Variant::Operator)p_op; + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + Variant *ret = (Variant *)r_return; + Variant::evaluate(op, *a, *b, *ret, *r_valid); +} + +void GDAPI godot_variant_set(godot_variant *p_self, const godot_variant *p_key, const godot_variant *p_value, bool *r_valid) { + Variant *self = (Variant *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + + self->set(*key, *value, r_valid); +} + +void GDAPI godot_variant_set_named(godot_variant *p_self, const godot_string_name *p_name, const godot_variant *p_value, bool *r_valid) { + Variant *self = (Variant *)p_self; + const StringName *name = (const StringName *)p_name; + const Variant *value = (const Variant *)p_value; + + self->set_named(*name, *value, *r_valid); +} + +void GDAPI godot_variant_set_keyed(godot_variant *p_self, const godot_variant *p_key, const godot_variant *p_value, bool *r_valid) { + Variant *self = (Variant *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + + self->set_keyed(*key, *value, *r_valid); +} + +void GDAPI godot_variant_set_indexed(godot_variant *p_self, godot_int p_index, const godot_variant *p_value, bool *r_valid, bool *r_oob) { + Variant *self = (Variant *)p_self; + const Variant *value = (const Variant *)p_value; + + self->set_indexed(p_index, value, *r_valid, *r_oob); +} + +godot_variant GDAPI godot_variant_get(const godot_variant *p_self, const godot_variant *p_key, bool *r_valid) { const Variant *self = (const Variant *)p_self; - const String *method = (const String *)p_method; - return self->has_method(*method); + const Variant *key = (const Variant *)p_key; + Variant ret; + + ret = self->get(*key, r_valid); + godot_variant result; + memnew_placement_custom(&result, Variant, Variant(ret)); + return result; } -godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other) { +godot_variant GDAPI godot_variant_get_named(const godot_variant *p_self, const godot_string_name *p_key, bool *r_valid) { const Variant *self = (const Variant *)p_self; - const Variant *other = (const Variant *)p_other; - return self->operator==(*other); + const StringName *key = (const StringName *)p_key; + Variant ret; + + ret = self->get_named(*key, *r_valid); + godot_variant result; + memnew_placement_custom(&result, Variant, Variant(ret)); + return result; } -godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other) { +godot_variant GDAPI godot_variant_get_keyed(const godot_variant *p_self, const godot_variant *p_key, bool *r_valid) { const Variant *self = (const Variant *)p_self; - const Variant *other = (const Variant *)p_other; - return self->operator<(*other); + const Variant *key = (const Variant *)p_key; + Variant ret; + + ret = self->get_keyed(*key, *r_valid); + godot_variant result; + memnew_placement_custom(&result, Variant, Variant(ret)); + return result; +} + +godot_variant GDAPI godot_variant_get_indexed(const godot_variant *p_self, godot_int p_index, bool *r_valid, bool *r_oob) { + const Variant *self = (const Variant *)p_self; + Variant ret; + + ret = self->get_indexed(p_index, *r_valid, *r_oob); + godot_variant result; + memnew_placement_custom(&result, Variant, Variant(ret)); + return result; +} + +/// Iteration. +bool GDAPI godot_variant_iter_init(const godot_variant *p_self, godot_variant *r_iter, bool *r_valid) { + const Variant *self = (const Variant *)p_self; + Variant *iter = (Variant *)r_iter; + + return self->iter_init(*iter, *r_valid); } -uint32_t GDAPI godot_variant_hash(const godot_variant *p_self) { +bool GDAPI godot_variant_iter_next(const godot_variant *p_self, godot_variant *r_iter, bool *r_valid) { const Variant *self = (const Variant *)p_self; - return self->hash(); + Variant *iter = (Variant *)r_iter; + + return self->iter_next(*iter, *r_valid); +} + +godot_variant GDAPI godot_variant_iter_get(const godot_variant *p_self, godot_variant *r_iter, bool *r_valid) { + const Variant *self = (const Variant *)p_self; + Variant *iter = (Variant *)r_iter; + + Variant result = self->iter_next(*iter, *r_valid); + godot_variant ret; + memnew_placement_custom(&ret, Variant, Variant(result)); + return ret; } +/// Variant functions. 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; @@ -621,27 +696,487 @@ godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self) { return self->booleanize(); } -void GDAPI godot_variant_destroy(godot_variant *p_self) { - Variant *self = (Variant *)p_self; - self->~Variant(); +void GDAPI godot_variant_blend(const godot_variant *p_a, const godot_variant *p_b, float p_c, godot_variant *r_dst) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + Variant *dst = (Variant *)r_dst; + Variant::blend(*a, *b, p_c, *dst); } -// GDNative core 1.1 +void GDAPI godot_variant_interpolate(const godot_variant *p_a, const godot_variant *p_b, float p_c, godot_variant *r_dst) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + Variant *dst = (Variant *)r_dst; + Variant::interpolate(*a, *b, p_c, *dst); +} -godot_string GDAPI godot_variant_get_operator_name(godot_variant_operator p_op) { - Variant::Operator op = (Variant::Operator)p_op; - godot_string raw_dest; - String *dest = (String *)&raw_dest; - memnew_placement(dest, String(Variant::get_operator_name(op))); // operator = is overloaded by String - return raw_dest; +godot_variant GDAPI godot_variant_duplicate(const godot_variant *p_self, godot_bool p_deep) { + const Variant *self = (const Variant *)p_self; + Variant result = self->duplicate(p_deep); + godot_variant ret; + memnew_placement_custom(&ret, Variant, Variant(result)); + return ret; } -void GDAPI godot_variant_evaluate(godot_variant_operator p_op, const godot_variant *p_a, const godot_variant *p_b, godot_variant *r_ret, godot_bool *r_valid) { - Variant::Operator op = (Variant::Operator)p_op; - const Variant *a = (const Variant *)p_a; - const Variant *b = (const Variant *)p_b; +godot_string GDAPI godot_variant_stringify(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + String result = *self; + godot_string ret; + memnew_placement_custom(&ret, String, String(result)); + return ret; +} + +// Discovery API + +/// Operators +godot_validated_operator_evaluator GDAPI godot_variant_get_validated_operator_evaluator(godot_variant_operator p_operator, godot_variant_type p_type_a, godot_variant_type p_type_b) { + return (godot_validated_operator_evaluator)Variant::get_validated_operator_evaluator((Variant::Operator)p_operator, (Variant::Type)p_type_a, (Variant::Type)p_type_b); +} + +godot_ptr_operator_evaluator GDAPI godot_variant_get_ptr_operator_evaluator(godot_variant_operator p_operator, godot_variant_type p_type_a, godot_variant_type p_type_b) { + return (godot_ptr_operator_evaluator)Variant::get_ptr_operator_evaluator((Variant::Operator)p_operator, (Variant::Type)p_type_a, (Variant::Type)p_type_b); +} + +godot_variant_type GDAPI godot_variant_get_operator_return_type(godot_variant_operator p_operator, godot_variant_type p_type_a, godot_variant_type p_type_b) { + return (godot_variant_type)Variant::get_operator_return_type((Variant::Operator)p_operator, (Variant::Type)p_type_a, (Variant::Type)p_type_b); +} + +godot_string GDAPI godot_variant_get_operator_name(godot_variant_operator p_operator) { + String op_name = Variant::get_operator_name((Variant::Operator)p_operator); + godot_string ret; + memnew_placement_custom(&ret, String, String(op_name)); + return ret; +} + +/// Built-in Methods + +bool GDAPI godot_variant_has_builtin_method(godot_variant_type p_type, const godot_string_name *p_method) { + return Variant::has_builtin_method((Variant::Type)p_type, *((const StringName *)p_method)); +} + +bool GDAPI godot_variant_has_builtin_method_with_cstring(godot_variant_type p_type, const char *p_method) { + return Variant::has_builtin_method((Variant::Type)p_type, StringName(p_method)); +} + +godot_validated_builtin_method GDAPI godot_variant_get_validated_builtin_method(godot_variant_type p_type, const godot_string_name *p_method) { + return (godot_validated_builtin_method)Variant::get_validated_builtin_method((Variant::Type)p_type, *((const StringName *)p_method)); +} + +godot_validated_builtin_method GDAPI godot_variant_get_validated_builtin_method_with_cstring(godot_variant_type p_type, const char *p_method) { + return (godot_validated_builtin_method)Variant::get_validated_builtin_method((Variant::Type)p_type, StringName(p_method)); +} + +godot_ptr_builtin_method GDAPI godot_variant_get_ptr_builtin_method(godot_variant_type p_type, const godot_string_name *p_method) { + return (godot_ptr_builtin_method)Variant::get_ptr_builtin_method((Variant::Type)p_type, *((const StringName *)p_method)); +} + +godot_ptr_builtin_method GDAPI godot_variant_get_ptr_builtin_method_with_cstring(godot_variant_type p_type, const char *p_method) { + return (godot_ptr_builtin_method)Variant::get_ptr_builtin_method((Variant::Type)p_type, StringName(p_method)); +} + +int GDAPI godot_variant_get_builtin_method_argument_count(godot_variant_type p_type, const godot_string_name *p_method) { + return Variant::get_builtin_method_argument_count((Variant::Type)p_type, *((const StringName *)p_method)); +} + +int GDAPI godot_variant_get_builtin_method_argument_count_with_cstring(godot_variant_type p_type, const char *p_method) { + return Variant::get_builtin_method_argument_count((Variant::Type)p_type, StringName(p_method)); +} + +godot_variant_type GDAPI godot_variant_get_builtin_method_argument_type(godot_variant_type p_type, const godot_string_name *p_method, int p_argument) { + return (godot_variant_type)Variant::get_builtin_method_argument_type((Variant::Type)p_type, *((const StringName *)p_method), p_argument); +} + +godot_variant_type GDAPI godot_variant_get_builtin_method_argument_type_with_cstring(godot_variant_type p_type, const char *p_method, int p_argument) { + return (godot_variant_type)Variant::get_builtin_method_argument_type((Variant::Type)p_type, StringName(p_method), p_argument); +} + +godot_string GDAPI godot_variant_get_builtin_method_argument_name(godot_variant_type p_type, const godot_string_name *p_method, int p_argument) { + String name = Variant::get_builtin_method_argument_name((Variant::Type)p_type, *((const StringName *)p_method), p_argument); + return *(godot_string *)&name; +} + +godot_string GDAPI godot_variant_get_builtin_method_argument_name_with_cstring(godot_variant_type p_type, const char *p_method, int p_argument) { + String name = Variant::get_builtin_method_argument_name((Variant::Type)p_type, StringName(p_method), p_argument); + return *(godot_string *)&name; +} + +bool GDAPI godot_variant_has_builtin_method_return_value(godot_variant_type p_type, const godot_string_name *p_method) { + return Variant::has_builtin_method_return_value((Variant::Type)p_type, *((const StringName *)p_method)); +} + +bool GDAPI godot_variant_has_builtin_method_return_value_with_cstring(godot_variant_type p_type, const char *p_method) { + return Variant::has_builtin_method_return_value((Variant::Type)p_type, StringName(p_method)); +} + +godot_variant_type GDAPI godot_variant_get_builtin_method_return_type(godot_variant_type p_type, const godot_string_name *p_method) { + return (godot_variant_type)Variant::get_builtin_method_return_type((Variant::Type)p_type, *((const StringName *)p_method)); +} + +godot_variant_type GDAPI godot_variant_get_builtin_method_return_type_with_cstring(godot_variant_type p_type, const char *p_method) { + return (godot_variant_type)Variant::get_builtin_method_return_type((Variant::Type)p_type, StringName(p_method)); +} + +bool GDAPI godot_variant_is_builtin_method_const(godot_variant_type p_type, const godot_string_name *p_method) { + return Variant::is_builtin_method_const((Variant::Type)p_type, *((const StringName *)p_method)); +} + +bool GDAPI godot_variant_is_builtin_method_const_with_cstring(godot_variant_type p_type, const char *p_method) { + return Variant::is_builtin_method_const((Variant::Type)p_type, StringName(p_method)); +} + +bool GDAPI godot_variant_is_builtin_method_vararg(godot_variant_type p_type, const godot_string_name *p_method) { + return Variant::is_builtin_method_vararg((Variant::Type)p_type, *((const StringName *)p_method)); +} + +bool GDAPI godot_variant_is_builtin_method_vararg_with_cstring(godot_variant_type p_type, const char *p_method) { + return Variant::is_builtin_method_vararg((Variant::Type)p_type, StringName(p_method)); +} + +int GDAPI godot_variant_get_builtin_method_count(godot_variant_type p_type) { + return Variant::get_builtin_method_count((Variant::Type)p_type); +} + +void GDAPI godot_variant_get_builtin_method_list(godot_variant_type p_type, godot_string_name *r_list) { + List<StringName> list; + Variant::get_builtin_method_list((Variant::Type)p_type, &list); + int i = 0; + for (const List<StringName>::Element *E = list.front(); E; E = E->next()) { + memnew_placement_custom(&r_list[i], StringName, StringName(E->get())); + } +} + +/// Constructors + +int GDAPI godot_variant_get_constructor_count(godot_variant_type p_type) { + return Variant::get_constructor_count((Variant::Type)p_type); +} + +godot_validated_constructor GDAPI godot_variant_get_validated_constructor(godot_variant_type p_type, int p_constructor) { + return (godot_validated_constructor)Variant::get_validated_constructor((Variant::Type)p_type, p_constructor); +} + +godot_ptr_constructor GDAPI godot_variant_get_ptr_constructor(godot_variant_type p_type, int p_constructor) { + return (godot_ptr_constructor)Variant::get_ptr_constructor((Variant::Type)p_type, p_constructor); +} + +int GDAPI godot_variant_get_constructor_argument_count(godot_variant_type p_type, int p_constructor) { + return Variant::get_constructor_argument_count((Variant::Type)p_type, p_constructor); +} + +godot_variant_type GDAPI godot_variant_get_constructor_argument_type(godot_variant_type p_type, int p_constructor, int p_argument) { + return (godot_variant_type)Variant::get_constructor_argument_type((Variant::Type)p_type, p_constructor, p_argument); +} + +godot_string GDAPI godot_variant_get_constructor_argument_name(godot_variant_type p_type, int p_constructor, int p_argument) { + String name = Variant::get_constructor_argument_name((Variant::Type)p_type, p_constructor, p_argument); + godot_string ret; + memnew_placement(&ret, String(name)); + return ret; +} + +void GDAPI godot_variant_construct(godot_variant_type p_type, godot_variant *p_base, const godot_variant **p_args, int p_argcount, godot_variant_call_error *r_error) { + Variant::construct((Variant::Type)p_type, *((Variant *)p_base), (const Variant **)p_args, p_argcount, *((Callable::CallError *)r_error)); +} + +/// Properties. +godot_variant_type GDAPI godot_variant_get_member_type(godot_variant_type p_type, const godot_string_name *p_member) { + return (godot_variant_type)Variant::get_member_type((Variant::Type)p_type, *((const StringName *)p_member)); +} + +godot_variant_type GDAPI godot_variant_get_member_type_with_cstring(godot_variant_type p_type, const char *p_member) { + return (godot_variant_type)Variant::get_member_type((Variant::Type)p_type, StringName(p_member)); +} + +int GDAPI godot_variant_get_member_count(godot_variant_type p_type) { + return Variant::get_member_count((Variant::Type)p_type); +} + +void GDAPI godot_variant_get_member_list(godot_variant_type p_type, godot_string_name *r_list) { + List<StringName> members; + Variant::get_member_list((Variant::Type)p_type, &members); + int i = 0; + for (const List<StringName>::Element *E = members.front(); E; E = E->next()) { + memnew_placement_custom(&r_list[i++], StringName, StringName(E->get())); + } +} + +godot_validated_setter GDAPI godot_variant_get_validated_setter(godot_variant_type p_type, const godot_string_name *p_member) { + return (godot_validated_setter)Variant::get_member_validated_setter((Variant::Type)p_type, *((const StringName *)p_member)); +} + +godot_validated_setter GDAPI godot_variant_get_validated_setter_with_cstring(godot_variant_type p_type, const char *p_member) { + return (godot_validated_setter)Variant::get_member_validated_setter((Variant::Type)p_type, StringName(p_member)); +} + +godot_validated_getter GDAPI godot_variant_get_validated_getter(godot_variant_type p_type, const godot_string_name *p_member) { + return (godot_validated_getter)Variant::get_member_validated_getter((Variant::Type)p_type, *((const StringName *)p_member)); +} + +godot_validated_getter GDAPI godot_variant_get_validated_getter_with_cstring(godot_variant_type p_type, const char *p_member) { + return (godot_validated_getter)Variant::get_member_validated_getter((Variant::Type)p_type, StringName(p_member)); +} + +godot_ptr_setter GDAPI godot_variant_get_ptr_setter(godot_variant_type p_type, const godot_string_name *p_member) { + return (godot_ptr_setter)Variant::get_member_ptr_setter((Variant::Type)p_type, *((const StringName *)p_member)); +} + +godot_ptr_setter GDAPI godot_variant_get_ptr_setter_with_cstring(godot_variant_type p_type, const char *p_member) { + return (godot_ptr_setter)Variant::get_member_ptr_setter((Variant::Type)p_type, StringName(p_member)); +} + +godot_ptr_getter GDAPI godot_variant_get_ptr_getter(godot_variant_type p_type, const godot_string_name *p_member) { + return (godot_ptr_getter)Variant::get_member_ptr_getter((Variant::Type)p_type, *((const StringName *)p_member)); +} + +godot_ptr_getter GDAPI godot_variant_get_ptr_getter_with_cstring(godot_variant_type p_type, const char *p_member) { + return (godot_ptr_getter)Variant::get_member_ptr_getter((Variant::Type)p_type, StringName(p_member)); +} + +/// Indexing. +bool GDAPI godot_variant_has_indexing(godot_variant_type p_type) { + return Variant::has_indexing((Variant::Type)p_type); +} + +godot_variant_type GDAPI godot_variant_get_indexed_element_type(godot_variant_type p_type) { + return (godot_variant_type)Variant::get_indexed_element_type((Variant::Type)p_type); +} + +godot_validated_indexed_setter GDAPI godot_variant_get_validated_indexed_setter(godot_variant_type p_type) { + return (godot_validated_indexed_setter)Variant::get_member_validated_indexed_setter((Variant::Type)p_type); +} + +godot_validated_indexed_getter GDAPI godot_variant_get_validated_indexed_getter(godot_variant_type p_type) { + return (godot_validated_indexed_getter)Variant::get_member_validated_indexed_getter((Variant::Type)p_type); +} + +godot_ptr_indexed_setter GDAPI godot_variant_get_ptr_indexed_setter(godot_variant_type p_type) { + return (godot_ptr_indexed_setter)Variant::get_member_ptr_indexed_setter((Variant::Type)p_type); +} + +godot_ptr_indexed_getter GDAPI godot_variant_get_ptr_indexed_getter(godot_variant_type p_type) { + return (godot_ptr_indexed_getter)Variant::get_member_ptr_indexed_getter((Variant::Type)p_type); +} + +uint64_t GDAPI godot_variant_get_indexed_size(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->get_indexed_size(); +} + +/// Keying. +bool GDAPI godot_variant_is_keyed(godot_variant_type p_type) { + return Variant::is_keyed((Variant::Type)p_type); +} + +godot_validated_keyed_setter GDAPI godot_variant_get_validated_keyed_setter(godot_variant_type p_type) { + return (godot_validated_keyed_setter)Variant::get_member_validated_keyed_setter((Variant::Type)p_type); +} + +godot_validated_keyed_getter GDAPI godot_variant_get_validated_keyed_getter(godot_variant_type p_type) { + return (godot_validated_keyed_getter)Variant::get_member_validated_keyed_getter((Variant::Type)p_type); +} + +godot_validated_keyed_checker GDAPI godot_variant_get_validated_keyed_checker(godot_variant_type p_type) { + return (godot_validated_keyed_checker)Variant::get_member_validated_keyed_checker((Variant::Type)p_type); +} + +godot_ptr_keyed_setter GDAPI godot_variant_get_ptr_keyed_setter(godot_variant_type p_type) { + return (godot_ptr_keyed_setter)Variant::get_member_ptr_keyed_setter((Variant::Type)p_type); +} + +godot_ptr_keyed_getter GDAPI godot_variant_get_ptr_keyed_getter(godot_variant_type p_type) { + return (godot_ptr_keyed_getter)Variant::get_member_ptr_keyed_getter((Variant::Type)p_type); +} + +godot_ptr_keyed_checker GDAPI godot_variant_get_ptr_keyed_checker(godot_variant_type p_type) { + return (godot_ptr_keyed_checker)Variant::get_member_ptr_keyed_checker((Variant::Type)p_type); +} + +/// Constants. +int GDAPI godot_variant_get_constants_count(godot_variant_type p_type) { + return Variant::get_constants_count_for_type((Variant::Type)p_type); +} + +void GDAPI godot_variant_get_constants_list(godot_variant_type p_type, godot_string_name *r_list) { + List<StringName> constants; + int i = 0; + Variant::get_constants_for_type((Variant::Type)p_type, &constants); + for (const List<StringName>::Element *E = constants.front(); E; E = E->next()) { + memnew_placement_custom(&r_list[i++], StringName, StringName(E->get())); + } +} + +bool GDAPI godot_variant_has_constant(godot_variant_type p_type, const godot_string_name *p_constant) { + return Variant::has_constant((Variant::Type)p_type, *((const StringName *)p_constant)); +} + +bool GDAPI godot_variant_has_constant_with_cstring(godot_variant_type p_type, const char *p_constant) { + return Variant::has_constant((Variant::Type)p_type, StringName(p_constant)); +} + +godot_variant GDAPI godot_variant_get_constant_value(godot_variant_type p_type, const godot_string_name *p_constant) { + Variant constant = Variant::get_constant_value((Variant::Type)p_type, *((const StringName *)p_constant)); + godot_variant ret; + memnew_placement_custom(&ret, Variant, Variant(constant)); + return ret; +} + +godot_variant GDAPI godot_variant_get_constant_value_with_cstring(godot_variant_type p_type, const char *p_constant) { + Variant constant = Variant::get_constant_value((Variant::Type)p_type, StringName(p_constant)); + godot_variant ret; + memnew_placement_custom(&ret, Variant, Variant(constant)); + return ret; +} + +/// Utilities. +bool GDAPI godot_variant_has_utility_function(const godot_string_name *p_function) { + return Variant::has_utility_function(*((const StringName *)p_function)); +} + +bool GDAPI godot_variant_has_utility_function_with_cstring(const char *p_function) { + return Variant::has_utility_function(StringName(p_function)); +} + +void GDAPI godot_variant_call_utility_function(const godot_string_name *p_function, godot_variant *r_ret, const godot_variant **p_args, int p_argument_count, godot_variant_call_error *r_error) { + const StringName *function = (const StringName *)p_function; Variant *ret = (Variant *)r_ret; - Variant::evaluate(op, *a, *b, *ret, *r_valid); + const Variant **args = (const Variant **)p_args; + Callable::CallError error; + + Variant::call_utility_function(*function, ret, args, p_argument_count, error); + + if (r_error) { + r_error->error = (godot_variant_call_error_error)error.error; + r_error->argument = error.argument; + r_error->expected = (godot_variant_type)error.expected; + } +} + +void GDAPI godot_variant_call_utility_function_with_cstring(const char *p_function, godot_variant *r_ret, const godot_variant **p_args, int p_argument_count, godot_variant_call_error *r_error) { + Variant *ret = (Variant *)r_ret; + const Variant **args = (const Variant **)p_args; + Callable::CallError error; + + Variant::call_utility_function(StringName(p_function), ret, args, p_argument_count, error); + + if (r_error) { + r_error->error = (godot_variant_call_error_error)error.error; + r_error->argument = error.argument; + r_error->expected = (godot_variant_type)error.expected; + } +} + +godot_variant_utility_function_type GDAPI godot_variant_get_utility_function_type(const godot_string_name *p_function) { + return (godot_variant_utility_function_type)Variant::get_utility_function_type(*((const StringName *)p_function)); +} + +godot_variant_utility_function_type GDAPI godot_variant_get_utility_function_type_with_cstring(const char *p_function) { + return (godot_variant_utility_function_type)Variant::get_utility_function_type(StringName(p_function)); +} + +int GDAPI godot_variant_get_utility_function_argument_count(const godot_string_name *p_function) { + return Variant::get_utility_function_argument_count(*((const StringName *)p_function)); +} + +int GDAPI godot_variant_get_utility_function_argument_count_with_cstring(const char *p_function) { + return Variant::get_utility_function_argument_count(StringName(p_function)); +} + +godot_variant_type GDAPI godot_variant_get_utility_function_argument_type(const godot_string_name *p_function, int p_argument) { + return (godot_variant_type)Variant::get_utility_function_argument_type(*((const StringName *)p_function), p_argument); +} + +godot_variant_type GDAPI godot_variant_get_utility_function_argument_type_with_cstring(const char *p_function, int p_argument) { + return (godot_variant_type)Variant::get_utility_function_argument_type(StringName(p_function), p_argument); +} + +godot_string GDAPI godot_variant_get_utility_function_argument_name(const godot_string_name *p_function, int p_argument) { + String argument_name = Variant::get_utility_function_argument_name(*((const StringName *)p_function), p_argument); + godot_string ret; + memnew_placement_custom(&ret, String, String(argument_name)); + return ret; +} + +godot_string GDAPI godot_variant_get_utility_function_argument_name_with_cstring(const char *p_function, int p_argument) { + String argument_name = Variant::get_utility_function_argument_name(StringName(p_function), p_argument); + godot_string ret; + memnew_placement_custom(&ret, String, String(argument_name)); + return ret; +} + +bool GDAPI godot_variant_has_utility_function_return_value(const godot_string_name *p_function) { + return Variant::has_utility_function_return_value(*((const StringName *)p_function)); +} + +bool GDAPI godot_variant_has_utility_function_return_value_with_cstring(const char *p_function) { + return Variant::has_utility_function_return_value(StringName(p_function)); +} + +godot_variant_type GDAPI godot_variant_get_utility_function_return_type(const godot_string_name *p_function) { + return (godot_variant_type)Variant::get_utility_function_return_type(*((const StringName *)p_function)); +} + +godot_variant_type GDAPI godot_variant_get_utility_function_return_type_with_cstring(const char *p_function) { + return (godot_variant_type)Variant::get_utility_function_return_type(StringName(p_function)); +} + +bool GDAPI godot_variant_is_utility_function_vararg(const godot_string_name *p_function) { + return Variant::is_utility_function_vararg(*((const StringName *)p_function)); +} + +bool GDAPI godot_variant_is_utility_function_vararg_with_cstring(const char *p_function) { + return Variant::is_utility_function_vararg(StringName(p_function)); +} + +int GDAPI godot_variant_get_utility_function_count() { + return Variant::get_utility_function_count(); +} + +void GDAPI godot_variant_get_utility_function_list(godot_string_name *r_functions) { + List<StringName> functions; + godot_string_name *func = r_functions; + Variant::get_utility_function_list(&functions); + + for (const List<StringName>::Element *E = functions.front(); E; E = E->next()) { + memnew_placement_custom(func++, StringName, StringName(E->get())); + } +} + +// Introspection. + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return (godot_variant_type)self->get_type(); +} + +bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string_name *p_method) { + const Variant *self = (const Variant *)p_self; + const StringName *method = (const StringName *)p_method; + return self->has_method(*method); +} + +bool GDAPI godot_variant_has_member(godot_variant_type p_type, const godot_string_name *p_member) { + return Variant::has_member((Variant::Type)p_type, *((const StringName *)p_member)); +} + +bool GDAPI godot_variant_has_key(const godot_variant *p_self, const godot_variant *p_key, bool *r_valid) { + const Variant *self = (const Variant *)p_self; + const Variant *key = (const Variant *)p_key; + return self->has_key(*key, *r_valid); +} + +godot_string GDAPI godot_variant_get_type_name(godot_variant_type p_type) { + String name = Variant::get_type_name((Variant::Type)p_type); + godot_string ret; + memnew_placement_custom(&ret, String, String(name)); + return ret; +} + +bool GDAPI godot_variant_can_convert(godot_variant_type p_from, godot_variant_type p_to) { + return Variant::can_convert((Variant::Type)p_from, (Variant::Type)p_to); +} + +bool GDAPI godot_variant_can_convert_strict(godot_variant_type p_from, godot_variant_type p_to) { + return Variant::can_convert_strict((Variant::Type)p_from, (Variant::Type)p_to); } #ifdef __cplusplus |