Skip to content

Commit

Permalink
Implement inherits_script() for NativeScript and PluginScript
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Aug 2, 2021
1 parent f2efa6f commit 2dcd064
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
22 changes: 19 additions & 3 deletions modules/gdnative/nativescript/nativescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,25 @@ void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder)
#endif

bool NativeScript::inherits_script(const Ref<Script> &p_script) const {
#ifndef _MSC_VER
#warning inheritance needs to be implemented in NativeScript
#endif
Ref<NativeScript> ns = p_script;
if (ns.is_null()) {
return false;
}

const NativeScriptDesc *other_s = ns->get_script_desc();
if (!other_s) {
return false;
}

const NativeScriptDesc *s = get_script_desc();

while (s) {
if (s == other_s) {
return true;
}
s = s->base_data;
}

return false;
}

Expand Down
17 changes: 14 additions & 3 deletions modules/gdnative/pluginscript/pluginscript_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,20 @@ bool PluginScript::can_instantiate() const {
}

bool PluginScript::inherits_script(const Ref<Script> &p_script) const {
#ifndef _MSC_VER
#warning inheritance needs to be implemented in PluginScript
#endif
Ref<PluginScript> ps = p_script;
if (ps.is_null()) {
return false;
}

const PluginScript *s = this;

while (s) {
if (s == p_script.ptr()) {
return true;
}
s = Object::cast_to<PluginScript>(s->_ref_base_parent.ptr());
}

return false;
}

Expand Down

0 comments on commit 2dcd064

Please sign in to comment.