godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.7k stars 528 forks source link

Give compile-time error if registering a class without its own `_bind_methods()` function #1448

Closed dsnopek closed 5 months ago

dsnopek commented 5 months ago

It's already a compile-time error if you make a class without a _bind_methods() that descends from a native class (like Node, Control, etc).

But as pointed out on issue https://github.com/godotengine/godot-cpp/issues/1430, if you make a class that descends from another extension class, there won't be a compile-time error because the parent class's _bind_methods() will get picked up, and some things won't work correctly (ex virtual method registration, like _ready(), as mentioned in the issue).

This PR attempts to make it a compile-time error if the class doesn't have its own _bind_methods(), ignoring any _bind_methods() inherited from its parent class.

This seems to work in my testing on GCC!

Fixes https://github.com/godotengine/godot-cpp/issues/1430

pupil1337 commented 5 months ago

I tested it, work good.

dsnopek commented 5 months ago

Thanks for the testing and review!~

dsnopek commented 4 months ago

Cherry-picked for 4.2 in PR https://github.com/godotengine/godot-cpp/pull/1465

dsnopek commented 4 months ago

Cherry-picked for 4.1 in PR https://github.com/godotengine/godot-cpp/pull/1466