From 23c310be7b6d1ce77029e765e4411e4fab2d1a40 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sun, 9 Apr 2017 13:26:48 +0200 Subject: [PATCH 1/2] Add _ClassDB.class_[g|s]et_property to ClassDB exposed methods --- core/bind/core_bind.cpp | 19 +++++++++++++++++++ core/bind/core_bind.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index c9c74094d3f..3fcb55e5d74 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2366,6 +2366,23 @@ Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) con return ret; } +Variant _ClassDB::get_property(Object *p_object, const StringName &p_property) const { + Variant ret; + ClassDB::get_property(p_object, p_property, ret); + return ret; +} + +Error _ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const { + Variant ret; + bool valid; + if (!ClassDB::set_property(p_object, p_property, p_value, &valid)) { + return ERR_UNAVAILABLE; + } else if (!valid) { + return ERR_INVALID_DATA; + } + return OK; +} + bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const { return ClassDB::has_method(p_class, p_method, p_no_inheritance); @@ -2438,6 +2455,8 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false)); ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property); + ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property); ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false)); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 1d231ff033e..64e540b1006 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -586,6 +586,8 @@ public: Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const; Array get_property_list(StringName p_class, bool p_no_inheritance = false) const; + Variant get_property(Object *p_object, const StringName &p_property) const; + Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const; bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const; From 42eba57badd70432093d8114a0e8e1fabe184e5c Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sun, 9 Apr 2017 14:04:01 +0200 Subject: [PATCH 2/2] Add return value in ClassDB.class_[g|s]et_property bindings --- core/bind/core_bind.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3fcb55e5d74..1bc6fc53534 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2455,8 +2455,8 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false)); ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property); - ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property); + ClassDB::bind_method(D_METHOD("class_get_property:Variant", "object", "property"), &_ClassDB::get_property); + ClassDB::bind_method(D_METHOD("class_set_property:Error", "object", "property", "value"), &_ClassDB::set_property); ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false));