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

Enums defined with enum classes in-engine are not using enum classes in godot-cpp #1620

Open
aaronfranke opened this issue Oct 10, 2024 · 1 comment

Comments

@aaronfranke
Copy link
Member

Godot version

Godot master

godot-cpp version

Master of godot-cpp 6facde3

System information

macOS 14.6.1 arm64

Issue description

Enums such as Key, MouseButton, MouseButtonMask, and more using enum class in-engine are not using enum class in godot-cpp, they are just using regular enum. Using enum class improves type safety, but I am not sure if Godot provides a mechanism for godot-cpp to know which enums are using enum class.

This issue is not super important because there is an easy workaround. In my project, I am using these defines that only get used when compiling as a module, and writing KEY_ in my code, which auto-replace when compiled as a module.

#if GODOT_MODULE
#define KEY_A Key::A
#define KEY_D Key::D
#define KEY_E Key::E
#define KEY_F Key::F
#define KEY_Q Key::Q
#define KEY_R Key::R
#define KEY_S Key::S
#define KEY_T Key::T
#define KEY_W Key::W
#define KEY_SHIFT Key::SHIFT

#define MOUSE_BUTTON_LEFT MouseButton::RIGHT
#define MOUSE_BUTTON_MASK_MIDDLE MouseButtonMask::MIDDLE
#define MOUSE_BUTTON_MASK_RIGHT MouseButtonMask::RIGHT
#define MOUSE_BUTTON_RIGHT MouseButton::RIGHT
#define MOUSE_BUTTON_WHEEL_UP MouseButton::WHEEL_UP
#define MOUSE_BUTTON_WHEEL_DOWN MouseButton::WHEEL_DOWN
#endif

Steps to reproduce

Try using one of the values in the Key enum in-engine vs in godot-cpp.

Minimal reproduction project

Trivial to reproduce with one line of code in a new godot-cpp GDExtension project.

@dsnopek
Copy link
Collaborator

dsnopek commented Oct 11, 2024

Godot doesn't provide this information to us, but I think it would be inappropriate to add it to extension_api.json, because it's so C++-specific or even really godot-cpp-specific because we're the only binding that has the goal of being API compatible with Godot (another theoretical C++ binding that doesn't have this goal could just decide to make all enums as enum class or enum per the type of API they wish to provide).

Maybe we could maintain a list of them in godot-cpp's binding_generator.py?

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

2 participants