summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
authorJordan Schidlowsky <jordan@winterpixel.com>2020-12-17 14:26:05 -0600
committerJordan Schidlowsky <jordan@noodlecake.com>2020-12-17 16:09:32 -0600
commit2d56e092765affde1904e76fe912329db0e9eab6 (patch)
treec3e918c0f993d75c4fbf13519eeb4b2db6bb8041 /core/variant
parent2c0d1c3b91a048c8aab6856c9821a98280ad82e6 (diff)
packed*arrays are pass by ref now. support duplicate and update documentation
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/variant_call.cpp9
-rw-r--r--core/variant/variant_setget.cpp18
2 files changed, 27 insertions, 0 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index d588c83809..0a1af591a1 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1316,6 +1316,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedByteArray, invert, sarray(), varray());
bind_method(PackedByteArray, subarray, sarray("from", "to"), varray());
bind_method(PackedByteArray, sort, sarray(), varray());
+ bind_method(PackedByteArray, duplicate, sarray(), varray());
bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
@@ -1342,6 +1343,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray());
bind_method(PackedInt32Array, to_byte_array, sarray(), varray());
bind_method(PackedInt32Array, sort, sarray(), varray());
+ bind_method(PackedInt32Array, duplicate, sarray(), varray());
/* Int64 Array */
@@ -1359,6 +1361,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray());
bind_method(PackedInt64Array, to_byte_array, sarray(), varray());
bind_method(PackedInt64Array, sort, sarray(), varray());
+ bind_method(PackedInt64Array, duplicate, sarray(), varray());
/* Float32 Array */
@@ -1376,6 +1379,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray());
bind_method(PackedFloat32Array, to_byte_array, sarray(), varray());
bind_method(PackedFloat32Array, sort, sarray(), varray());
+ bind_method(PackedFloat32Array, duplicate, sarray(), varray());
/* Float64 Array */
@@ -1393,6 +1397,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray());
bind_method(PackedFloat64Array, to_byte_array, sarray(), varray());
bind_method(PackedFloat64Array, sort, sarray(), varray());
+ bind_method(PackedFloat64Array, duplicate, sarray(), varray());
/* String Array */
@@ -1410,6 +1415,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedStringArray, subarray, sarray("from", "to"), varray());
bind_method(PackedStringArray, to_byte_array, sarray(), varray());
bind_method(PackedStringArray, sort, sarray(), varray());
+ bind_method(PackedStringArray, duplicate, sarray(), varray());
/* Vector2 Array */
@@ -1427,6 +1433,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray());
bind_method(PackedVector2Array, to_byte_array, sarray(), varray());
bind_method(PackedVector2Array, sort, sarray(), varray());
+ bind_method(PackedVector2Array, duplicate, sarray(), varray());
/* Vector3 Array */
@@ -1444,6 +1451,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray());
bind_method(PackedVector3Array, to_byte_array, sarray(), varray());
bind_method(PackedVector3Array, sort, sarray(), varray());
+ bind_method(PackedVector3Array, duplicate, sarray(), varray());
/* Color Array */
@@ -1461,6 +1469,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedColorArray, subarray, sarray("from", "to"), varray());
bind_method(PackedColorArray, to_byte_array, sarray(), varray());
bind_method(PackedColorArray, sort, sarray(), varray());
+ bind_method(PackedColorArray, duplicate, sarray(), varray());
/* Register constants */
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index cee7465205..28cf8ef967 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -2023,6 +2023,24 @@ Variant Variant::duplicate(bool deep) const {
return operator Dictionary().duplicate(deep);
case ARRAY:
return operator Array().duplicate(deep);
+ case PACKED_BYTE_ARRAY:
+ return operator Vector<uint8_t>().duplicate();
+ case PACKED_INT32_ARRAY:
+ return operator Vector<int32_t>().duplicate();
+ case PACKED_INT64_ARRAY:
+ return operator Vector<int64_t>().duplicate();
+ case PACKED_FLOAT32_ARRAY:
+ return operator Vector<float>().duplicate();
+ case PACKED_FLOAT64_ARRAY:
+ return operator Vector<double>().duplicate();
+ case PACKED_STRING_ARRAY:
+ return operator Vector<String>().duplicate();
+ case PACKED_VECTOR2_ARRAY:
+ return operator Vector<Vector2>().duplicate();
+ case PACKED_VECTOR3_ARRAY:
+ return operator Vector<Vector3>().duplicate();
+ case PACKED_COLOR_ARRAY:
+ return operator Vector<Color>().duplicate();
default:
return *this;
}