-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Single-character String literal (int
type)
#11704
Comments
If it wasn't for the fact that we allowed single quote strings I'd have pushed for using the C syntax for this but unfortunately that's not convenient I'm not sure about the suggested syntax here, but something achieving this would be helpful |
Yeah, I would probably also have suggested |
It could be fast with better constant support. const char = "a".unicode_at(0) it would be evaluated only once for the script, but currently it's not allowed, even if it's technically a constant expression. const chr = char(10) but we don't have utility method that does the opposite. |
That's true, though i would argue this pattern would still rarely be used since it's way longer than just |
|
I think this perspective is a little too technical. That being said, |
This is a very fine line between purity and practicality, so I don't have any absolute arguments. You're right, it could work as you described and wouldn't cause any major practical contradictions. However, in my opinion, supporting character literals at the language level while simultaneously lacking a character type has at least conceptual inconsistencies:
|
I was on board with this until I saw your proposed syntax. |
@Jesusemora got any better ideas? |
Describe the project you are working on
Godot internals.
Describe the problem or limitation you are having in your project
GDScript does not have a convenient way to express 'single character' values.
Ideally, it would have a literal type for them.
Single characters are most useful for their performance benefits, because they do not allocate memory (as opposed to
String
).Some existing APIs already use single characters as arguments or return types (
int
type). It is currently inconvenient to call them (a
is unicode97
):string.get_slicec(97, 0)
(ref)input.is_key_label_pressed(97)
(ref)string.unicode_at(0) == 97
(ref)string.lpadc(97)
String.chr(97)
(ref)"a"
, but may be used transitively (through functions).Describe the feature / enhancement and how it helps to overcome the problem or limitation
There should be a single-character literal for GDScript. Since GDScript uses
int
to describe characters in existing APIs, it would evaluate toint
(UTF-32).Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I propose the following syntax (analogous to others using String prefixes):
If this enhancement will not be used often, can it be worked around with a few lines of script?
It is possible to use unicode value literals:
These can be looked up on sites like unicodelookup.com.
It is also possible to use GDScript:
However, this is slow.
Is there a reason why this should be core and not an add-on in the asset library?
It's GDScript syntax.
The text was updated successfully, but these errors were encountered: