diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 25a93dfc7..12040509c 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -149,6 +149,15 @@ struct EngineClassRegistration { } }; +template +struct MemberPointerTraits; + +template +struct MemberPointerTraits { + using result_type = Result; + using object_type = Object; +}; + } // namespace internal } // namespace godot @@ -369,6 +378,12 @@ public: _gde_binding_reference_callback, \ }; \ \ + template \ + typename internal::MemberPointerTraits::result_type _get_data_member() { return (this->*T); } \ + \ + template \ + void _set_data_member(typename internal::MemberPointerTraits::result_type t) { (this->*T) = t; } \ + \ private: // Don't use this for your classes, use GDCLASS() instead. diff --git a/include/godot_cpp/core/object.hpp b/include/godot_cpp/core/object.hpp index c1f106922..0780364ab 100644 --- a/include/godot_cpp/core/object.hpp +++ b/include/godot_cpp/core/object.hpp @@ -51,6 +51,14 @@ #define ADD_GROUP(m_name, m_prefix) godot::ClassDB::add_property_group(get_class_static(), m_name, m_prefix) #define ADD_SUBGROUP(m_name, m_prefix) godot::ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix) #define ADD_PROPERTY(m_property, m_setter, m_getter) godot::ClassDB::add_property(get_class_static(), m_property, m_setter, m_getter) +#define AUTO_ADD_PROPERTY(p_property, p_method) \ + { \ + auto get = &godot::internal::MemberPointerTraits::object_type::_get_data_member; \ + auto set = &godot::internal::MemberPointerTraits::object_type::_set_data_member; \ + ClassDB::bind_method(D_METHOD(StringName("get") + StringName(&#p_method[1])), get); \ + ClassDB::bind_method(D_METHOD(StringName("set") + StringName(&#p_method[1])), set); \ + ClassDB::add_property(get_class_static(), p_property, StringName("set") + StringName(&#p_method[1]), StringName("get") + StringName(&#p_method[1])); \ + } #define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) godot::ClassDB::add_property(get_class_static(), m_property, m_setter, m_getter, m_index) namespace godot {