diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 950f4a62d804..b89667df6018 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -197,10 +197,10 @@ void Variant::_register_variant_constructors() { add_constructor(sarray("object", "signal")); add_constructor>(sarray()); - add_constructor>(sarray("from")); + add_constructor(sarray("from")); add_constructor>(sarray()); - add_constructor>(sarray("from")); + add_constructor(sarray("from")); add_constructor(sarray("base", "type", "class_name", "script")); add_constructor>(sarray("from")); add_constructor>(sarray("from")); diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h index ef7bf2dfc235..1d4374e90768 100644 --- a/core/variant/variant_construct.h +++ b/core/variant/variant_construct.h @@ -394,6 +394,84 @@ class VariantConstructorSignalArgs { } }; +class VariantConstructorDictionaryDuplicate { +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::DICTIONARY; + return; + } + + const Dictionary &src_dict = *VariantGetInternalPtr::get_ptr(p_args[0]); + r_ret = src_dict.duplicate(); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + const Dictionary &src_dict = *VariantGetInternalPtr::get_ptr(p_args[0]); + *r_ret = src_dict.duplicate(); + } + + static void ptr_construct(void *base, const void **p_args) { + const Dictionary &src_dict = PtrToArg::convert(p_args[0]); + Dictionary dst_dict = src_dict.duplicate(); + + PtrConstruct::construct(dst_dict, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::DICTIONARY; + } + + static Variant::Type get_base_type() { + return Variant::DICTIONARY; + } +}; + +class VariantConstructorArrayDuplicate { +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; + } + + const Array &src_arr = *VariantGetInternalPtr::get_ptr(p_args[0]); + r_ret = src_arr.duplicate(); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + const Array &src_arr = *VariantGetInternalPtr::get_ptr(p_args[0]); + *r_ret = src_arr.duplicate(); + } + + static void ptr_construct(void *base, const void **p_args) { + const Array &src_arr = PtrToArg::convert(p_args[0]); + Array dst_arr = src_arr.duplicate(); + + PtrConstruct::construct(dst_arr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::ARRAY; + } + + static Variant::Type get_base_type() { + return Variant::ARRAY; + } +}; + class VariantConstructorTypedArray { public: static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index c4fec5a72956..6bb3f501265e 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -66,7 +66,7 @@ - Returns the same array as [param from]. If you need a copy of the array, use [method duplicate]. + Constructs an [Array] as a [i]shallow[/i] copy of the given [Array], similarly to [method duplicate]. diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index a5a50b4c6a1e..da57393d59a6 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -153,7 +153,7 @@ - Returns the same dictionary as [param from]. If you need a copy of the dictionary, use [method duplicate]. + Constructs a [Dictionary] as a [i]shallow[/i] copy of the given [Dictionary], similarly to [method duplicate].