Ability to convert from nodes or other non resource with a get_rid() function to a rid

This commit is contained in:
Juan Linietsky 2015-04-24 20:45:07 -03:00
parent 807a811fad
commit 1f8e3117dd
3 changed files with 12 additions and 2 deletions

View file

@ -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");
}

View file

@ -56,6 +56,7 @@ public:
StringName _iter_init;
StringName _iter_next;
StringName _iter_get;
StringName get_rid;
};

View file

@ -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<const RID*>(_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 {