-
-
Notifications
You must be signed in to change notification settings - Fork 23.4k
Implement a @meta
annotation
#111312
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
base: master
Are you sure you want to change the base?
Implement a @meta
annotation
#111312
Conversation
…methods on Script
…notation->resolved_arguments
Having the uid as a separate file, but at the same time the metadata as an annotation inside the script looks really confusing. |
In the attempt to solve godotengine/godot-proposals#1316 , I don't think it ever crossed most contributor's minds to utilize a single |
Btw in your commits you ping user with |
Unlike UIDs, the keys/values here are user-defined at the class and class-member level, so I think the text of the script is an appropriate place for them. That said, I understand that calling this "metadata" could be confusing given that other kinds of script metadata (like UIDs) already exist and live elsewhere. The name was inspired by |
What application of custom annotations from the original proposal did you have in mind? I think this PR unblocks the original |
+@TokageItLab , since you took some interest in PR #102516. |
Closes godotengine/godot-proposals#1316
This PR implements a new
@meta
annotation similar to the one described in #102516 (comment).The
@meta(name: StringName, value: Variant = true)
annotation allows script authors to tag classes and class members in their scripts withStringName
-keyed arbitrary metadata. This metadata can then be inspected at runtime by calling one of the following newScript
methods:Array[StringName] Script.get_script_meta_list() const
- gets a list of all@meta
names appearing in the script.Array[Dictionary] Script.get_script_meta(name: StringName) const
- gets a list of dictionaries describing each appearance of@meta
having the givenname
in the script.Usage example
Specifications
@meta
annotation can target classes, constants, signals, properties, and methods. This includes arbitrarily deep inner classes and their members.@meta
can annotate a given target multiple times, even with the samename
.@meta
must be a constant expression. If omitted, it defaults totrue
.Script.get_script_meta(name)
returns a list of dictionaries, where each dictionary describes an instance of@meta(name, ...)
in the script. The format of the dictionary is described in the docs added in bc46b32. It includes the target name, target type, container class name (if any), and metadata value.Notes
@meta
is a new builtin annotation and doesn't add support for custom user-defined annotations. However, I believe it should unblock most of the use cases in Allow custom GDScript annotations which can be read at runtime godot-proposals#1316.@meta
is for constant key-value metadata. The goal was not to implement something like Python decorators in Godot.@meta
for GDScript, but support for (e.g.) a companion C#[Meta(...)]
attribute hooked up to the same getter interface onScript
should be feasible.