diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/extension/extension_api_dump.cpp | 3 | ||||
-rw-r--r-- | core/variant/array.h | 2 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 8 | ||||
-rw-r--r-- | core/variant/variant_construct.cpp | 1 | ||||
-rw-r--r-- | core/variant/variant_construct.h | 76 |
5 files changed, 89 insertions, 1 deletions
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index 06cd98264a..e6e0fff266 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -46,6 +46,9 @@ static String get_type_name(const PropertyInfo &p_info) { return p_info.hint_string + "*"; } } + if (p_info.type == Variant::ARRAY && (p_info.hint == PROPERTY_HINT_ARRAY_TYPE)) { + return String("typedarray::") + p_info.hint_string; + } if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM))) { return String("enum::") + String(p_info.class_name); } 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: |