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

[SDL3] C++ headers & modules #9771

Open
CXCubeHD opened this issue May 11, 2024 · 7 comments
Open

[SDL3] C++ headers & modules #9771

CXCubeHD opened this issue May 11, 2024 · 7 comments
Assignees
Milestone

Comments

@CXCubeHD
Copy link

CXCubeHD commented May 11, 2024

Since SDL3 is in development, I would like to propose that there should be some kind of C++ header generation. This would make using headers way more comfortable as a C++ user. I really like the way VulkanHpp was implemented.

On top of that SDL3 should have optional (by default off) C++ 20 Module support (just like VulkanHpp aswell). Much work has been done on the compiler and CMake side to make this as easy as possible (read (this article)[https://www.kitware.com/import-cmake-the-experiment-is-over/] for more).

I would really love to see this happen

Edit:

For good C++ adaptation I would expect the following:

  1. Namespacing:

Example:

sdl::Delay(2000); // sdl namespace is lowercase, types & functions are PascalCase
sdl::Event e;
  1. Flags as enum class:

(some flags will have to be renamed because of clarity)

Example:

SDL_SOMEFLAG_FLAG1
sdl::SomeFlag::Flag1

SDL_SOMEFLAG_FLAG1 | SDL_SOMEFLAG_FLAG2

sdl::SomeFlag::Flag1 | sdl::SomeFlag::Flag2
@CXCubeHD CXCubeHD changed the title [SDL3] C++ headers [SDL3] C++ headers & modules May 11, 2024
@Sackzement
Copy link
Contributor

Please no lower-case sdl, this looks so wrong. :)

@CXCubeHD
Copy link
Author

CXCubeHD commented May 11, 2024

Please no lower-case sdl, this looks so wrong. :)

I guess uppercase SDL would also be okay then. It could even be made configurable through a macro and cmake (just like VulkanHpp)

@slouken
Copy link
Collaborator

slouken commented May 12, 2024

Feel free to submit a PR for this.

@slouken slouken added this to the 3.x milestone May 12, 2024
@CXCubeHD
Copy link
Author

Feel free to submit a PR for this.

Yo I feel like I can do this but I need to get more familiar with the code / project structure 👌

@TerensTare
Copy link

I'm pretty sure this can easily be solved by writing a parser that goes through all the file and generates an intermediate representation in json, which is then converted into a C++ module file. The parser can hugely simplify the process of generating bindings to other languages. This is the approach taken by both ImGui (see here ) and Raylib (see here ) to generate some kind of "API dump" in JSON/other format, which is then translated into the target language code.

Finally, since by adopting this parser the target becomes larger than C++ bindings, I think it should be part of a separate repo that is only used by maintainers of bindings in other languages.

@madebr
Copy link
Contributor

madebr commented May 22, 2024

@TerensTare
See #6337
If you know how to write such a parser, that would enable lots of other things.

@TerensTare
Copy link

I will try to write a set up a parser with minimal features that can be easily improved and come back with a PR.

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

No branches or pull requests

5 participants