mirror of
https://github.com/godotengine/godot.git
synced 2024-11-26 14:13:10 +00:00
Make dict2inst
to work with arbitrary _init
parameters
This is achieved by skipping initializer call while creating an instance of a GDScript. This is implemented by passing -1 as an argument count to `_new` and interpreting any value below 0 to mean that the initializer should not be called during instantiation, because internal members of an instance are going to be overridden afterwards.
This commit is contained in:
parent
f870118323
commit
7001d06f9d
@ -103,15 +103,14 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
|
|||||||
instance->owner->set_script_instance(instance);
|
instance->owner->set_script_instance(instance);
|
||||||
|
|
||||||
/* STEP 2, INITIALIZE AND CONSTRUCT */
|
/* STEP 2, INITIALIZE AND CONSTRUCT */
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexLock lock(GDScriptLanguage::singleton->lock);
|
MutexLock lock(GDScriptLanguage::singleton->lock);
|
||||||
|
|
||||||
instances.insert(instance->owner);
|
instances.insert(instance->owner);
|
||||||
}
|
}
|
||||||
|
if (p_argcount < 0) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
initializer->call(instance, p_args, p_argcount, r_error);
|
initializer->call(instance, p_args, p_argcount, r_error);
|
||||||
|
|
||||||
if (r_error.error != Callable::CallError::CALL_OK) {
|
if (r_error.error != Callable::CallError::CALL_OK) {
|
||||||
instance->script = Ref<GDScript>();
|
instance->script = Ref<GDScript>();
|
||||||
instance->owner->set_script_instance(nullptr);
|
instance->owner->set_script_instance(nullptr);
|
||||||
@ -119,10 +118,8 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
|
|||||||
MutexLock lock(GDScriptLanguage::singleton->lock);
|
MutexLock lock(GDScriptLanguage::singleton->lock);
|
||||||
instances.erase(p_owner);
|
instances.erase(p_owner);
|
||||||
}
|
}
|
||||||
|
ERR_FAIL_V_MSG(nullptr, "Error constructing a GDScriptInstance.");
|
||||||
ERR_FAIL_COND_V(r_error.error != Callable::CallError::CALL_OK, nullptr); //error constructing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@TODO make thread safe
|
//@TODO make thread safe
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -1197,8 +1197,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
r_ret = gdscr->_new(nullptr, -1 /*skip initializer*/, r_error);
|
||||||
r_ret = gdscr->_new(nullptr, 0, r_error);
|
|
||||||
|
|
||||||
GDScriptInstance *ins = static_cast<GDScriptInstance *>(static_cast<Object *>(r_ret)->get_script_instance());
|
GDScriptInstance *ins = static_cast<GDScriptInstance *>(static_cast<Object *>(r_ret)->get_script_instance());
|
||||||
Ref<GDScript> gd_ref = ins->get_script();
|
Ref<GDScript> gd_ref = ins->get_script();
|
||||||
|
Loading…
Reference in New Issue
Block a user