diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-09 09:18:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 09:18:57 +0200 |
commit | fa1a66dd687a5aa39c9e0500db3e62056f634a97 (patch) | |
tree | 6d4b6001599914fbfa5a6353b7124c88749cfb5c | |
parent | 85399a91706f9f163ccbd3274ea2d511dd8564d0 (diff) | |
parent | 2dcd064056cd7905ef1559e9f35aa223a583d225 (diff) |
Merge pull request #51180 from RandomShaper/native_script_inherits
Implement inherits_script() for NativeScript and PluginScript
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 22 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_script.cpp | 17 |
2 files changed, 33 insertions, 6 deletions
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index f3a0e9603f..26d3aed702 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -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; } diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 7fc8178e34..5380858582 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -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; } |