Skip to content

Conversation

@mikomikotaishi
Copy link
Contributor

This pull request adds support for C++20 modules, by enabling the macro BUILD_RAYLIB_CPP_MODULES at build time. It gives access to the module raylib, which is imported by writing import raylib;.

@mikomikotaishi
Copy link
Contributor Author

@RobLoach Hi, are there any concerns regarding this PR before it could be merged?

@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jun 2, 2025

Also, I have a question about the library. Is there a particular reason you chose to continue use PascalCase for the methods/functions, rather than just camelCase? I know that in the original Raylib library the functions use PascalCase names, but besides that I feel like it is more difficult to distinguish function and class names if both are PascalCase. If that makes sense, would you considering allowing a build option using a preprocessor macro to toggle whether methods are PascalCase or camelCase?

@RobLoach
Copy link
Owner

RobLoach commented Jun 2, 2025

Thanks for pushing this forwards. Just hadn't had a look.

Is there a particular reason you chose to continue use PascalCase for the methods/functions, rather than just camelCase?

While I understand the C++ convention is usually camelCase, keeping them the same as raylib has a few benefits...

  1. Means there's no question what it should be in raylib-cpp
  2. Makes porting from C to C++ easier as you don't have to consider the cases when porting

A preprocessor would be cool, but I'd fear it may result in a lot of maintenace issues. Could we have them be aliases or something so that the code could work in either case?

@RobLoach RobLoach merged commit be2efd4 into RobLoach:master Jun 2, 2025
8 checks passed
@mikomikotaishi
Copy link
Contributor Author

mikomikotaishi commented Jun 2, 2025

Ah, sorry for my impatience.

As far as I'm aware there is no way to alias function names with the keyword using - only class names and variables/constants can be renamed. That being said, there'd only have to be one implementation, if we could put the preprocessor changes inside the function signature. That would look something like this:

// example of Color::ToInt()
#ifndef RAYLIBCPP_CAMEL_CASE
[[nodiscard]] int ToInt() const 
#else 
[[nodiscard]] int toInt() const
#endif
{ return ::ColorToInt(*this); }

etc.

Now I understand that won't be the most elegant thing in the world, and would probably make the code look a lot harder to read, but it's the only thing I can think of.

That being said we could rename all the methods by doing something like

#ifdef RAYLIBCPP_CAMEL_CASE
// ...
#define TO_INT toInt
// ...
#define TO_INT ToInt
#else

#endif

Also, getters and setters could also be affected by the presence of that macro if we altered the GETTER() and GETTERSETTER() macro accordingly.

@RobLoach
Copy link
Owner

RobLoach commented Jun 3, 2025

I think keeping inline with the original raylib conventions may be best for the case. While changing it will make it feel more like C++, changing it will deviate from raylib, and break existing usage.

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

Successfully merging this pull request may close these issues.

2 participants