Add append_array() method to Array class
(cherry picked from commit 9f23a94b8a
)
This commit is contained in:
parent
f39c71e32d
commit
98774000e2
4 changed files with 24 additions and 0 deletions
|
@ -117,6 +117,11 @@ void Array::push_back(const Variant &p_value) {
|
||||||
_p->array.push_back(p_value);
|
_p->array.push_back(p_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Array::append_array(const Array &p_array) {
|
||||||
|
|
||||||
|
_p->array.append_array(p_array._p->array);
|
||||||
|
}
|
||||||
|
|
||||||
Error Array::resize(int p_new_size) {
|
Error Array::resize(int p_new_size) {
|
||||||
|
|
||||||
return _p->array.resize(p_new_size);
|
return _p->array.resize(p_new_size);
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
|
|
||||||
void push_back(const Variant &p_value);
|
void push_back(const Variant &p_value);
|
||||||
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
|
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
|
||||||
|
void append_array(const Array &p_array);
|
||||||
Error resize(int p_new_size);
|
Error resize(int p_new_size);
|
||||||
|
|
||||||
void insert(int p_pos, const Variant &p_value);
|
void insert(int p_pos, const Variant &p_value);
|
||||||
|
|
|
@ -534,6 +534,7 @@ struct _VariantCall {
|
||||||
VCALL_LOCALMEM0R(Array, pop_back);
|
VCALL_LOCALMEM0R(Array, pop_back);
|
||||||
VCALL_LOCALMEM0R(Array, pop_front);
|
VCALL_LOCALMEM0R(Array, pop_front);
|
||||||
VCALL_LOCALMEM1(Array, append);
|
VCALL_LOCALMEM1(Array, append);
|
||||||
|
VCALL_LOCALMEM1(Array, append_array);
|
||||||
VCALL_LOCALMEM1(Array, resize);
|
VCALL_LOCALMEM1(Array, resize);
|
||||||
VCALL_LOCALMEM2(Array, insert);
|
VCALL_LOCALMEM2(Array, insert);
|
||||||
VCALL_LOCALMEM1(Array, remove);
|
VCALL_LOCALMEM1(Array, remove);
|
||||||
|
@ -1799,6 +1800,7 @@ void register_variant_methods() {
|
||||||
ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
|
ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
|
||||||
ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
|
ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
|
||||||
ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray());
|
ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray());
|
||||||
|
ADDFUNC1NC(ARRAY, NIL, Array, append_array, ARRAY, "array", varray());
|
||||||
ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray());
|
ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray());
|
||||||
ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
|
ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
|
||||||
ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray());
|
ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray());
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
var array2 = [3, "Four"]
|
var array2 = [3, "Four"]
|
||||||
print(array1 + array2) # ["One", 2, 3, "Four"]
|
print(array1 + array2) # ["One", 2, 3, "Four"]
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
|
Note that concatenating with [code]+=[/code] operator will create a new array. If you want to append another array to an existing array, [method append_array] is more efficient.
|
||||||
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
|
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
|
@ -95,6 +96,21 @@
|
||||||
Appends an element at the end of the array (alias of [method push_back]).
|
Appends an element at the end of the array (alias of [method push_back]).
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="append_array">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="array" type="Array">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Appends another array at the end of this array.
|
||||||
|
[codeblock]
|
||||||
|
var array1 = [1, 2, 3]
|
||||||
|
var array2 = [4, 5, 6]
|
||||||
|
array1.append_array(array2)
|
||||||
|
print(array1) # Prints [1, 2, 3, 4, 5, 6].
|
||||||
|
[/codeblock]
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="back">
|
<method name="back">
|
||||||
<return type="Variant">
|
<return type="Variant">
|
||||||
</return>
|
</return>
|
||||||
|
|
Loading…
Reference in a new issue