fix cast_to

This commit is contained in:
karroffel
2018-04-06 01:39:35 +02:00
parent b3d705c898
commit d420613bd2
3 changed files with 25 additions and 15 deletions

View File

@@ -495,7 +495,19 @@ void register_signal(String name, Args... varargs)
template<class T>
T *Object::cast_to(const Object *obj)
{
if (godot::_TagDB::is_type_compatible(T::___get_type_tag(), obj->_type_tag)) {
const void *have_tag = godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);
if (have_tag) {
if (!godot::_TagDB::is_type_known(have_tag)) {
have_tag = nullptr;
}
}
if (!have_tag) {
have_tag = obj->_type_tag;
}
if (godot::_TagDB::is_type_compatible(T::___get_type_tag(), have_tag)) {
return (T::___CLASS_IS_SCRIPT) ? godot::as<T>(obj) : (T *) obj;
} else {
return nullptr;

View File

@@ -6,8 +6,8 @@ namespace godot {
namespace _TagDB {
void register_type(const void *type_tag, const void *base_type_tag);
bool is_type_known(const void *type_tag);
void register_global_type(const char *name, const void *type_tag, const void *base_type_tag);
bool is_type_compatible(const void *type_tag, const void *base_type_tag);
}