diff options
author | George Marques <george@gmarqu.es> | 2021-09-10 10:40:32 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 10:40:32 -0300 |
commit | 0b484c5f5fc89e35bece5cb9df3380bec6540b7e (patch) | |
tree | 3dd86172f2d8b312955d0cc1a208fee365b6ce91 /modules | |
parent | 11e457e594844f6defc5c105ecb78f6b6c49cfff (diff) | |
parent | 861bb3a48890e7c46310f47ce19eaa8578bbc566 (diff) |
Merge pull request #51456 from SaracenOne/super_init_fix
Call _init on base class if one does not exist.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 15 | ||||
-rw-r--r-- | modules/gdscript/gdscript.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 5409b3ff79..bc8801b8b9 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -87,6 +87,19 @@ Object *GDScriptNativeClass::instantiate() { return ClassDB::instantiate(name); } +GDScriptFunction *GDScript::_super_constructor(GDScript *p_script) { + if (p_script->initializer) { + return p_script->initializer; + } else { + GDScript *base = p_script->_base; + if (base != nullptr) { + return _super_constructor(base); + } else { + return nullptr; + } + } +} + void GDScript::_super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error) { GDScript *base = p_script->_base; if (base != nullptr) { @@ -135,6 +148,8 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco if (p_argcount < 0) { return instance; } + + initializer = _super_constructor(this); if (initializer != nullptr) { initializer->call(instance, p_args, p_argcount, r_error); if (r_error.error != Callable::CallError::CALL_OK) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index a6fd7b3b5d..791f8a1431 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -130,6 +130,7 @@ class GDScript : public Script { SelfList<GDScriptFunctionState>::List pending_func_states; + GDScriptFunction *_super_constructor(GDScript *p_script); void _super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error); GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error); |