Merge pull request #95930 from aaronfranke/bind-array-set
Bind Array and Packed*Array `get` and `set` functions
This commit is contained in:
commit
83b2ca3107
|
@ -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());
|
||||
|
|
|
@ -422,6 +422,13 @@
|
|||
[b]Note:[/b] Unlike with the [code][][/code] operator ([code]array[0][/code]), an error is generated without stopping project execution.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Variant" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the element at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_typed_builtin" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
|
@ -693,6 +700,14 @@
|
|||
Returns the index of the [b]last[/b] element of the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find_custom].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set">
|
||||
<return type="void" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<param index="1" name="value" type="Variant" />
|
||||
<description>
|
||||
Sets the value of the element at the given [param index] to the given [param value]. This will not change the size of the array, it only changes the value at an index already in the array. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="shuffle">
|
||||
<return type="void" />
|
||||
<description>
|
||||
|
|
|
@ -460,6 +460,14 @@
|
|||
Returns [code]true[/code] if the two dictionaries contain the same keys and values, inner [Dictionary] and [Array] keys and values are compared recursively.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set">
|
||||
<return type="bool" />
|
||||
<param index="0" name="key" type="Variant" />
|
||||
<param index="1" name="value" type="Variant" />
|
||||
<description>
|
||||
Sets the value of the element at the given [param key] to the given [param value]. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="size" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
|
|
|
@ -307,6 +307,13 @@
|
|||
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the byte at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_string_from_ascii" qualifiers="const">
|
||||
<return type="String" />
|
||||
<description>
|
||||
|
|
|
@ -94,6 +94,13 @@
|
|||
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Color" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the [Color] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="Color" />
|
||||
|
|
|
@ -93,6 +93,13 @@
|
|||
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="float" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the 32-bit float at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="float" />
|
||||
|
|
|
@ -94,6 +94,13 @@
|
|||
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="float" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the 64-bit float at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="float" />
|
||||
|
|
|
@ -90,6 +90,13 @@
|
|||
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the 32-bit integer at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="int" />
|
||||
|
|
|
@ -91,6 +91,13 @@
|
|||
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the 64-bit integer at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="int" />
|
||||
|
|
|
@ -97,6 +97,13 @@
|
|||
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="String" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the [String] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="String" />
|
||||
|
|
|
@ -98,6 +98,13 @@
|
|||
[b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Vector2" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the [Vector2] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="Vector2" />
|
||||
|
|
|
@ -97,6 +97,13 @@
|
|||
[b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Vector3" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the [Vector3] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="Vector3" />
|
||||
|
|
|
@ -96,6 +96,13 @@
|
|||
[b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns the [Vector4] at the given [param index] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="has" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="value" type="Vector4" />
|
||||
|
|
Loading…
Reference in New Issue