-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add support for fully static classes #3955
Comments
See the comment. |
You can have static classes, just not static properties. Your static class can extend Static properties can be hacked with a constant that is assigned a dictionary, since dictionary can still be modified. For example: class_name TextUtils
extends Reference
# It's a trick to have a static instance of RegEx.
# Bad bad hacks, but it does the job and static class > autoload helper.
const _cache := {}
static func bbcode_add_code_color(bbcode_text := "") -> String:
if not _cache.has("regex_bbcode_code"):
_cache["regex_bbcode_code"] = RegEx.new()
_cache["regex_bbcode_code"].compile("\\[code\\].+?\\[\\/code\\]")
return _cache["regex_bbcode_code"].sub(bbcode_text, "[color=#c6c4e1]$0[/color]", true) |
oh really? thats cool.
One problem is that the class keyword seems to still have predefined functions of object regardless if I derive from Refrence |
Reference extends Object. There is nothing smaller than object. What is your proposal about? |
Its about bloat, I need a strictly empty static class, or be able to overwrite functions for auto loads. |
Not sure if you know, but a script doesn't actually have to extend anything unless it's attached to a node or resource. You can have standalone scripts that don't inherit anything at all (but you can't autoload them because then they have to be a Node). |
If you omit the |
this is correct I basically need a empty object with just GC and type info |
This comment is not to discuss the request (not for or against it), simply to give a general tour of "static" in Godot from a person who is not used yet to the Godot ways. The goal here is to paraphrase the discussion and to give a tour of the general state of affairs, except with generalistic programming terms and concepts that can be understood by outsiders. About singletons (not exactly about "static", but related) :
About static :
Back to static variables:
As a conclusion :
|
Closing in favor of #5025, which is more scoped to what would actually need to be implemented. |
Describe the project you are working on
A yieldable signal dispatcher
Describe the problem or limitation you are having in your project
Right now I am using a autoload but Nodes have members that clash with the names I want to give it for consistency
usually the answer is to use a static class but gd script doesn't support those.
You can't overwrite the functions either.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Please either support static classes and variables along side static functions,
or allow us to autoload a base node type that has no members at all.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
possibly like above or like this...
If this enhancement will not be used often, can it be worked around with a few lines of script?
It would be most likely be used for utility classes, It cannot be worked around
Is there a reason why this should be core and not an add-on in the asset library?
This would be use in cases you want to reduce size of executable and have naming consistency
The text was updated successfully, but these errors were encountered: