-
Notifications
You must be signed in to change notification settings - Fork 196
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
[Godot] Implement access modifiers, private and protected, to GDScript to protect a class member from being accessed externally. #734
Conversation
It is simply GDScript, also what is the reasoning for closing your Godot PR? |
This is great! Has anyone tested this ? Also does this work with autocomplete? |
Autocomplete, or intelliguess, is planned (in the check list of the top thread). But according to original proposal, it seems that the original proposer wanted to make a ordered list of the autocomplete. |
Btw, currently a C# script can painlessly access a private or protected member in GDScript, but I haven't checked runtime and vm how C#'s |
0ab9d2b
to
8c028ad
Compare
9415389
to
96bfd8a
Compare
5abf1f5
to
e03fdc9
Compare
I just now reviewed my Java guidebook and surfed the internet and found that one can access a private/protected member/method via reflection. So I removed two tasks about access protection from being accessed via |
Closed because i need some devs' help from godot who are expert in GDScript, plus the current setting of this pr is kinda unsatisfying. |
This is my first contribution to redot. If there is any mistake, please let me know and I'm here to hear that. :)
Trying implementing redot-proposal-#7.
This pr provides RDScript users a way to protect their members accessibility, and prevent any illegal access from external classes.
We will have
private
andprotected
keywords in RDScript soon:Introduction of new annotations
private
The
private
keyword allows a member (currently a constant, a variable or a method) to be accessible only within the current class scope:protected
The
protected
keyword allows a member (currently a constant, a variable or a method) to be accessible only within the current class scope, or the scope of derived classes:Common features:
private
orprotected
will hide its documentation from auto-generated doc API, even if you use##
to document it (except@export_*
-ed properties and signals).Spelling rules:
[optional access modifier] [optional static] var/func/signal/const <identifier>
(Note:signal
andconst
cannot be modified withstatic
.)static
must be placed afterprivate
orprotected
Note:
This pr only prevents from direct access to external members. For accessing members by reflection (i.e. by
set()
,get()
orcall()
and the variants of these methods), due to potential performance impact during runtime and complexity of implementation, it's not protected. This means that this pr only provides shallow access restriction, and the following styles of access will be protected:And allowing reflectional methods to access private/protected method is how oops languages like Java and C# works.
Remaining WIP
reduce_identifier()
andreduce_call()
. (RDScriptAnalyzer)Discussion about if(Having checked the documentation about whether it is better to use keywords or annotations, I decided to use keywords instead)@private
and@protected
should be keywords or annotations. Allow@export_*
work with@private
and@protected
Not sure whether an invalid access should pop an error or a warning. (Warning / error system)(Thinking twice and I turned it into a warning system, which is an error by default).gd
and.out
files. (Unit test)Remaining WIP after being converted into Review
Tracking after this PR gets merged:
Closes Redot-Engine/redot-proposals#7