1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-14 13:41:12 +00:00

Bind Array get and set functions

This commit is contained in:
Aaron Franke
2024-08-21 19:26:21 -07:00
parent 506d6e427a
commit cc9f2b58a0
13 changed files with 124 additions and 0 deletions

View File

@@ -657,7 +657,23 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
} \
};
#define VARCALL_PACKED_GETTER(m_packed_type, m_return_type) \
static m_return_type func_##m_packed_type##_get(m_packed_type *p_instance, int64_t p_index) { \
return p_instance->get(p_index); \
}
struct _VariantCall {
VARCALL_PACKED_GETTER(PackedByteArray, uint8_t)
VARCALL_PACKED_GETTER(PackedColorArray, Color)
VARCALL_PACKED_GETTER(PackedFloat32Array, float)
VARCALL_PACKED_GETTER(PackedFloat64Array, double)
VARCALL_PACKED_GETTER(PackedInt32Array, int32_t)
VARCALL_PACKED_GETTER(PackedInt64Array, int64_t)
VARCALL_PACKED_GETTER(PackedStringArray, String)
VARCALL_PACKED_GETTER(PackedVector2Array, Vector2)
VARCALL_PACKED_GETTER(PackedVector3Array, Vector3)
VARCALL_PACKED_GETTER(PackedVector4Array, Vector4)
static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) {
String s;
if (p_instance->size() > 0) {
@@ -2268,6 +2284,7 @@ static void _register_variant_builtin_methods_misc() {
bind_method(Dictionary, duplicate, sarray("deep"), varray(false));
bind_method(Dictionary, get, sarray("key", "default"), varray(Variant()));
bind_method(Dictionary, get_or_add, sarray("key", "default"), varray(Variant()));
bind_method(Dictionary, set, sarray("key", "value"), varray());
bind_method(Dictionary, is_typed, sarray(), varray());
bind_method(Dictionary, is_typed_key, sarray(), varray());
bind_method(Dictionary, is_typed_value, sarray(), varray());
@@ -2293,6 +2310,8 @@ static void _register_variant_builtin_methods_array() {
bind_method(Array, clear, sarray(), varray());
bind_method(Array, hash, sarray(), varray());
bind_method(Array, assign, sarray("array"), varray());
bind_method(Array, get, sarray("index"), varray());
bind_method(Array, set, sarray("index", "value"), varray());
bind_method(Array, push_back, sarray("value"), varray());
bind_method(Array, push_front, sarray("value"), varray());
bind_method(Array, append, sarray("value"), varray());
@@ -2337,6 +2356,18 @@ static void _register_variant_builtin_methods_array() {
bind_method(Array, make_read_only, sarray(), varray());
bind_method(Array, is_read_only, sarray(), varray());
/* Packed*Array get (see VARCALL_PACKED_GETTER macro) */
bind_function(PackedByteArray, get, _VariantCall::func_PackedByteArray_get, sarray("index"), varray());
bind_function(PackedColorArray, get, _VariantCall::func_PackedColorArray_get, sarray("index"), varray());
bind_function(PackedFloat32Array, get, _VariantCall::func_PackedFloat32Array_get, sarray("index"), varray());
bind_function(PackedFloat64Array, get, _VariantCall::func_PackedFloat64Array_get, sarray("index"), varray());
bind_function(PackedInt32Array, get, _VariantCall::func_PackedInt32Array_get, sarray("index"), varray());
bind_function(PackedInt64Array, get, _VariantCall::func_PackedInt64Array_get, sarray("index"), varray());
bind_function(PackedStringArray, get, _VariantCall::func_PackedStringArray_get, sarray("index"), varray());
bind_function(PackedVector2Array, get, _VariantCall::func_PackedVector2Array_get, sarray("index"), varray());
bind_function(PackedVector3Array, get, _VariantCall::func_PackedVector3Array_get, sarray("index"), varray());
bind_function(PackedVector4Array, get, _VariantCall::func_PackedVector4Array_get, sarray("index"), varray());
/* Byte Array */
bind_method(PackedByteArray, size, sarray(), varray());
bind_method(PackedByteArray, is_empty, sarray(), varray());