-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement read-only dictionaries. #61087
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
BTW, the only thing I miss for adding this to GDScript is some better error reporting. Function calls (like |
@vnen I am not sure, I added the code so it reports an error when you set to variant_setget.cpp, so I am not sure why it is not working for you. |
Nevermind, I had to use something else for this. |
* Add ability to set them read only. * If read-only, it can't be modified. This is added in order to optionally make const dictionaries (and eventually arrays) properly read-only in GDScript.
d759ecd
to
e6c443a
Compare
Alright, should now work as intended. |
@vnen It will throw a generic invalid set index error, but you can check in the VM whether an error happened and check if the base is a dictionary and is readonly and show the relevant thing. |
@reduz now it does throw an error when trying to set, so it's good to go. |
Thanks! |
This is added in order to optionally make const dictionaries (and eventually arrays) properly read-only in GDScript.
Implementation notes: This is implemented in a way that should have little to no cost if read-only is disabled. The main problem is that C++ does not necessarily prefer const overloads, so it may be possible that a non-const one is used to read data (and not modify it). For this a copy needs to be made to ensure no contents are overwritten.
In practice though, this should never happen because in no place Godot APIs take pointers or references to dictionaries for just reading, and the binder API also does not support this.