diff options
-rw-r--r-- | core/variant/variant.h | 1 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 17 | ||||
-rw-r--r-- | doc/classes/Array.xml | 2 | ||||
-rw-r--r-- | editor/doc_tools.cpp | 1 |
4 files changed, 19 insertions, 2 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h index fff59c43a6..b9294de77d 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -655,6 +655,7 @@ public: static bool has_indexing(Variant::Type p_type); static Variant::Type get_indexed_element_type(Variant::Type p_type); + static uint32_t get_indexed_element_usage(Variant::Type p_type); typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool *oob); typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool *oob); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index a74556d88f..ba37e15f31 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -389,6 +389,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.write[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -460,6 +461,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.write[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -515,6 +517,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -564,6 +567,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v m_accessor[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -613,6 +617,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.m_set(index, PtrToArg<m_elem_type>::convert(member)); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -683,6 +688,7 @@ struct VariantIndexedSetGet_Array { v.set(index, PtrToArg<Variant>::convert(member)); } static Variant::Type get_index_type() { return Variant::NIL; } + static uint32_t get_index_usage() { return PROPERTY_USAGE_NIL_IS_VARIANT; } static uint64_t get_indexed_size(const Variant *base) { return 0; } }; @@ -768,6 +774,7 @@ struct VariantIndexedSetGet_String { } } static Variant::Type get_index_type() { return Variant::STRING; } + static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; } static uint64_t get_indexed_size(const Variant *base) { return VariantInternal::get_string(base)->length(); } }; @@ -812,6 +819,7 @@ struct VariantIndexedSetGet_String { v[index] = PtrToArg<Variant>::convert(member); \ } \ static Variant::Type get_index_type() { return Variant::NIL; } \ + static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -852,7 +860,8 @@ struct VariantIndexedSetterGetterInfo { uint64_t (*get_indexed_size)(const Variant *base) = nullptr; - Variant::Type index_type; + Variant::Type index_type = Variant::NIL; + uint32_t index_usage = PROPERTY_USAGE_DEFAULT; bool valid = false; }; @@ -872,6 +881,7 @@ static void register_indexed_member(Variant::Type p_type) { sgi.ptr_getter = T::ptr_get; sgi.index_type = T::get_index_type(); + sgi.index_usage = T::get_index_usage(); sgi.get_indexed_size = T::get_indexed_size; sgi.valid = true; @@ -920,6 +930,11 @@ Variant::Type Variant::get_indexed_element_type(Variant::Type p_type) { return variant_indexed_setters_getters[p_type].index_type; } +uint32_t Variant::get_indexed_element_usage(Variant::Type p_type) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, PROPERTY_USAGE_DEFAULT); + return variant_indexed_setters_getters[p_type].index_usage; +} + Variant::ValidatedIndexedSetter Variant::get_member_validated_indexed_setter(Variant::Type p_type) { ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); return variant_indexed_setters_getters[p_type].validated_setter; diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 21ccf79fe2..ce4d7693d8 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -679,7 +679,7 @@ </description> </operator> <operator name="operator []"> - <return type="void" /> + <return type="Variant" /> <param index="0" name="index" type="int" /> <description> Returns a reference to the element of type [Variant] at the specified location. Arrays start at index 0. [param index] can be a zero or positive value to start from the beginning, or a negative value to start from the end. Out-of-bounds array access causes a run-time error, which will result in an error being printed and the project execution pausing if run from the editor. diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index c675060b2b..5bdef32c60 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -750,6 +750,7 @@ void DocTools::generate(bool p_basic_types) { MethodInfo mi; mi.name = "operator []"; mi.return_val.type = Variant::get_indexed_element_type(Variant::Type(i)); + mi.return_val.usage = Variant::get_indexed_element_usage(Variant::Type(i)); PropertyInfo arg; arg.name = "index"; arg.type = Variant::INT; |