You've already forked godot
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user