Automatically call the _init function on base class if one does not exist.

This commit is contained in:
SaracenOne 2021-08-10 02:39:42 +01:00
parent f3ddc14d38
commit 861bb3a488
2 changed files with 16 additions and 0 deletions

View File

@ -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) {

View File

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