summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-09-23 10:24:46 +0200
committerGitHub <noreply@github.com>2022-09-23 10:24:46 +0200
commit006e345695a0448acefd63dcb726a07b63cb1d0d (patch)
tree78e020ad93b2525718e1d65999d853442f2a870c /core/variant
parent03410efa15b88fc1e55476efb6b47d5079d34c96 (diff)
parent163257d51bd103588da246d39ab5d10afaf15c09 (diff)
Merge pull request #65817 from bruvzg/typed_array
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/array.h2
-rw-r--r--core/variant/variant_call.cpp8
-rw-r--r--core/variant/variant_construct.cpp1
-rw-r--r--core/variant/variant_construct.h76
4 files changed, 86 insertions, 1 deletions
diff --git a/core/variant/array.h b/core/variant/array.h
index c007376734..3d9a794969 100644
--- a/core/variant/array.h
+++ b/core/variant/array.h
@@ -47,7 +47,6 @@ class Array {
void _unref() const;
protected:
- Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
bool _assign(const Array &p_array);
public:
@@ -131,6 +130,7 @@ public:
void set_read_only(bool p_enable);
bool is_read_only() const;
+ Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
Array(const Array &p_from);
Array();
~Array();
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index a62b8a24a0..1831f7b72a 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2066,6 +2066,14 @@ static void _register_variant_builtin_methods() {
bind_method(Array, all, sarray("method"), varray());
bind_method(Array, max, sarray(), varray());
bind_method(Array, min, sarray(), varray());
+ bind_method(Array, typed_assign, sarray("array"), varray());
+ bind_method(Array, set_typed, sarray("type", "class_name", "script"), varray());
+ bind_method(Array, is_typed, sarray(), varray());
+ bind_method(Array, get_typed_builtin, sarray(), varray());
+ bind_method(Array, get_typed_class_name, sarray(), varray());
+ bind_method(Array, get_typed_script, sarray(), varray());
+ bind_method(Array, set_read_only, sarray("enable"), varray());
+ bind_method(Array, is_read_only, sarray(), varray());
/* Byte Array */
bind_method(PackedByteArray, size, sarray(), varray());
diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp
index d048f45737..3b88dc11ca 100644
--- a/core/variant/variant_construct.cpp
+++ b/core/variant/variant_construct.cpp
@@ -200,6 +200,7 @@ void Variant::_register_variant_constructors() {
add_constructor<VariantConstructNoArgs<Array>>(sarray());
add_constructor<VariantConstructor<Array, Array>>(sarray("from"));
+ add_constructor<VariantConstructorTypedArray>(sarray("base", "type", "class_name", "script"));
add_constructor<VariantConstructorToArray<PackedByteArray>>(sarray("from"));
add_constructor<VariantConstructorToArray<PackedInt32Array>>(sarray("from"));
add_constructor<VariantConstructorToArray<PackedInt64Array>>(sarray("from"));
diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h
index 58a0f34c1e..34d228f4d2 100644
--- a/core/variant/variant_construct.h
+++ b/core/variant/variant_construct.h
@@ -336,6 +336,82 @@ public:
}
};
+class VariantConstructorTypedArray {
+public:
+ static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) {
+ if (p_args[0]->get_type() != Variant::ARRAY) {
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::ARRAY;
+ return;
+ }
+
+ if (p_args[1]->get_type() != Variant::INT) {
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 1;
+ r_error.expected = Variant::INT;
+ return;
+ }
+
+ if (p_args[2]->get_type() != Variant::STRING_NAME) {
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 2;
+ r_error.expected = Variant::STRING_NAME;
+ return;
+ }
+
+ const Array &base_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]);
+ const uint32_t type = p_args[1]->operator uint32_t();
+ const StringName &class_name = *VariantGetInternalPtr<StringName>::get_ptr(p_args[2]);
+ r_ret = Array(base_arr, type, class_name, *p_args[3]);
+ }
+
+ static inline void validated_construct(Variant *r_ret, const Variant **p_args) {
+ const Array &base_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]);
+ const uint32_t type = p_args[1]->operator uint32_t();
+ const StringName &class_name = *VariantGetInternalPtr<StringName>::get_ptr(p_args[2]);
+ *r_ret = Array(base_arr, type, class_name, *p_args[3]);
+ }
+
+ static void ptr_construct(void *base, const void **p_args) {
+ const Array &base_arr = PtrToArg<Array>::convert(p_args[0]);
+ const uint32_t type = PtrToArg<uint32_t>::convert(p_args[1]);
+ const StringName &class_name = PtrToArg<StringName>::convert(p_args[2]);
+ const Variant &script = PtrToArg<Variant>::convert(p_args[3]);
+ Array dst_arr = Array(base_arr, type, class_name, script);
+
+ PtrConstruct<Array>::construct(dst_arr, base);
+ }
+
+ static int get_argument_count() {
+ return 4;
+ }
+
+ static Variant::Type get_argument_type(int p_arg) {
+ switch (p_arg) {
+ case 0: {
+ return Variant::ARRAY;
+ } break;
+ case 1: {
+ return Variant::INT;
+ } break;
+ case 2: {
+ return Variant::STRING_NAME;
+ } break;
+ case 3: {
+ return Variant::NIL;
+ } break;
+ default: {
+ return Variant::NIL;
+ } break;
+ }
+ }
+
+ static Variant::Type get_base_type() {
+ return Variant::ARRAY;
+ }
+};
+
template <class T>
class VariantConstructorToArray {
public: