godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.74k stars 575 forks source link

Add automatic generation of getters and setters to GDCLASS and a helper macro for using them #1401

Open TeagabC opened 8 months ago

TeagabC commented 8 months ago

First time PR here.

This lets you add properties without defining setters and getters. Example usage:

class Example : public Node {
  GDCLASS(Example, Node)
protected:
  static void _bind_methods();
public:
  int x;
};

void Example::_bind_methods() {
  AUTO_ADD_PROPERTY(PropertyInfo(Variant::INT, "x"), &Example::x);
}

It achieves it by adding templated getters and setters in GDCLASS. Is this something you would consider adding support for? Thanks

dsnopek commented 8 months ago

Thanks!

However, one of the design goals of godot-cpp is to be as API compatible with Godot modules as possible, allowing GDExtensions to optionally be compiled as modules, and for code to freely move between modules and GDExtensions.

So, in order to add something like this to godot-cpp, support for it would first need to be added to Godot itself.