summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMarc Gilleron <marc.gilleron@gmail.com>2022-09-18 22:23:49 +0100
committerMarc Gilleron <marc.gilleron@gmail.com>2022-09-18 22:23:49 +0100
commit99c004f6890ad0198b65e63c2ec429cad6a6291e (patch)
tree12e714ed0dbabf5144477785490dadfcf6724097 /include
parent3276688c825308199e8be6f6e7f9e90822d50643 (diff)
downloadredot-cpp-99c004f6890ad0198b65e63c2ec429cad6a6291e.tar.gz
Add `Object::cast_to` for `const Object*`
Diffstat (limited to 'include')
-rw-r--r--include/godot_cpp/core/object.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/godot_cpp/core/object.hpp b/include/godot_cpp/core/object.hpp
index 3acf827..6feea5a 100644
--- a/include/godot_cpp/core/object.hpp
+++ b/include/godot_cpp/core/object.hpp
@@ -144,6 +144,18 @@ T *Object::cast_to(Object *p_object) {
return reinterpret_cast<T *>(internal::gdn_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
}
+template <class T>
+const T *Object::cast_to(const Object *p_object) {
+ if (p_object == nullptr) {
+ return nullptr;
+ }
+ GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));
+ if (casted == nullptr) {
+ return nullptr;
+ }
+ return reinterpret_cast<const T *>(internal::gdn_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
+}
+
} // namespace godot
#endif // ! GODOT_OBJECT_HPP