1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Implement read-only arrays

Arrays can be set as read-only and thus cannot be modified. Assigning
the array will create an editable copy.

Similar to is already done to read-only dictionaries.
This commit is contained in:
George Marques
2022-05-17 14:14:42 -03:00
parent 7ea8cde983
commit 023b1d7f5a
3 changed files with 72 additions and 1 deletions

View File

@@ -624,6 +624,11 @@ struct VariantIndexedSetGet_Array {
PtrToArg<Variant>::encode(v[index], member);
}
static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) {
if (VariantGetInternalPtr<Array>::get_ptr(base)->is_read_only()) {
*valid = false;
*oob = true;
return;
}
int64_t size = VariantGetInternalPtr<Array>::get_ptr(base)->size();
if (index < 0) {
index += size;
@@ -638,6 +643,10 @@ struct VariantIndexedSetGet_Array {
*valid = true;
}
static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) {
if (VariantGetInternalPtr<Array>::get_ptr(base)->is_read_only()) {
*oob = true;
return;
}
int64_t size = VariantGetInternalPtr<Array>::get_ptr(base)->size();
if (index < 0) {
index += size;