From 1f8e3117dd8643b9c6d6127a891a0f4673479fa2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 24 Apr 2015 20:45:07 -0300 Subject: [PATCH] Ability to convert from nodes or other non resource with a get_rid() function to a rid --- core/core_string_names.cpp | 1 + core/core_string_names.h | 1 + core/variant.cpp | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 1fafc8110a4..d0cd19768ff 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -42,6 +42,7 @@ CoreStringNames::CoreStringNames() { _iter_init=StaticCString::create("_iter_init"); _iter_next=StaticCString::create("_iter_next"); _iter_get=StaticCString::create("_iter_get"); + get_rid=StaticCString::create("get_rid"); } diff --git a/core/core_string_names.h b/core/core_string_names.h index bf32e5f8c19..8bda1f3f790 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -56,6 +56,7 @@ public: StringName _iter_init; StringName _iter_next; StringName _iter_get; + StringName get_rid; }; diff --git a/core/variant.cpp b/core/variant.cpp index a85f288620a..e0c4b4244dc 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -32,7 +32,7 @@ #include "scene/main/node.h" #include "scene/gui/control.h" #include "io/marshalls.h" - +#include "core_string_names.h" @@ -1430,8 +1430,16 @@ Variant::operator RID() const { return *reinterpret_cast(_data._mem); else if (type==OBJECT && !_get_obj().ref.is_null()) { return _get_obj().ref.get_rid(); - } else + } else if (type==OBJECT && _get_obj().obj) { + Variant::CallError ce; + Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid,NULL,0,ce); + if (ce.error==Variant::CallError::CALL_OK && ret.get_type()==Variant::_RID) { + return ret; + } return RID(); + } else { + return RID(); + } } Variant::operator Object*() const {