Skip to content
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

Move String case conversion methods to core (snake_case, PascalCase, camelCase etc) #719

Closed
Xrayez opened this issue Apr 16, 2020 · 3 comments · Fixed by godotengine/godot#63902
Milestone

Comments

@Xrayez
Copy link
Contributor

Xrayez commented Apr 16, 2020

Describe the project you are working on:
Goost - Godot Engine Extension.

Working on code generators, bindings generators, template engines, and transpilers for Godot Engine.
See my gdgen python package for instance.

Describe the problem or limitation you are having in your project:
GDScript and core API is written in snake_case. This presents a problem for languages which use either PascalCase or camelCase conventions, so the entire API needs to be converted (see mono, gdnative/pluginscript modules).

Also when working on a GDScript-to-C++ transpiler I immediately stumbled upon an issue with having to convert "unnamed" classes (without class_name), so GDScript's file basename which can be written in the snake_case.gd needs to be converted to PascalCase for C++ classes. There are many other use cases ofcourse. Background: #565, #119.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I'd like to see at least the following methods to be added to the String class:

  • snake_to_camel_case
  • snake_to_pascal_case

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Some methods are already implemented as used by mono module, it's a matter of moving them to the String class. Preserves names prefixed with/without an underscore, useful for determining private/public access specifiers implicitly. Related: #641.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not a few lines. It's a matter of copy-and-pasting existing implementations if talking about C++ specifically, but additional work is required to port this to GDScript. But mostly, these are not even necessary to expose, it would be enough that those methods can be simply moved to core without exposing them to scripting if they are too specific for most users.

Is there a reason why this should be core and not an add-on in the asset library?:
I personally expect this to be present on the core level, yet again it's not necessary for those methods to be exposed to scripting in the first place.

@Xrayez
Copy link
Contributor Author

Xrayez commented Jun 30, 2020

See also Documentation infrastructure work package section which somewhat supports this proposal:

We need a system to switch references to API methods easily from snake_case to PascalCase, depending on the scripting language you are using.

@me2beats
Copy link

me2beats commented Oct 7, 2020

need them too for creating plugins to convert script paths to class names
while they are not there, I've created gdscript methods (gist)

@akien-mga
Copy link
Member

I think that's a good idea, refactoring the existing APIs similar to what is suggested here: godotengine/godot#52141 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants