GDScript: partially allow some functions on invalid scripts
+ always default initialize static variables + dont invalidate script when dependant scripts don't compile/resolve
This commit is contained in:
parent
505da68b26
commit
7f7114c008
|
@ -115,7 +115,7 @@ Variant GDScriptNativeClass::callp(const StringName &p_method, const Variant **p
|
||||||
}
|
}
|
||||||
|
|
||||||
GDScriptFunction *GDScript::_super_constructor(GDScript *p_script) {
|
GDScriptFunction *GDScript::_super_constructor(GDScript *p_script) {
|
||||||
if (p_script->initializer) {
|
if (likely(p_script->valid) && p_script->initializer) {
|
||||||
return p_script->initializer;
|
return p_script->initializer;
|
||||||
} else {
|
} else {
|
||||||
GDScript *base_src = p_script->_base;
|
GDScript *base_src = p_script->_base;
|
||||||
|
@ -136,7 +136,11 @@ void GDScript::_super_implicit_constructor(GDScript *p_script, GDScriptInstance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ERR_FAIL_NULL(p_script->implicit_initializer);
|
ERR_FAIL_NULL(p_script->implicit_initializer);
|
||||||
p_script->implicit_initializer->call(p_instance, nullptr, 0, r_error);
|
if (likely(valid)) {
|
||||||
|
p_script->implicit_initializer->call(p_instance, nullptr, 0, r_error);
|
||||||
|
} else {
|
||||||
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error) {
|
GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error) {
|
||||||
|
@ -662,7 +666,7 @@ String GDScript::_get_debug_path() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error GDScript::_static_init() {
|
Error GDScript::_static_init() {
|
||||||
if (static_initializer) {
|
if (likely(valid) && static_initializer) {
|
||||||
Callable::CallError call_err;
|
Callable::CallError call_err;
|
||||||
static_initializer->call(nullptr, nullptr, 0, call_err);
|
static_initializer->call(nullptr, nullptr, 0, call_err);
|
||||||
if (call_err.error != Callable::CallError::CALL_OK) {
|
if (call_err.error != Callable::CallError::CALL_OK) {
|
||||||
|
@ -679,8 +683,6 @@ Error GDScript::_static_init() {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
|
||||||
|
|
||||||
void GDScript::_static_default_init() {
|
void GDScript::_static_default_init() {
|
||||||
for (const KeyValue<StringName, MemberInfo> &E : static_variables_indices) {
|
for (const KeyValue<StringName, MemberInfo> &E : static_variables_indices) {
|
||||||
const GDScriptDataType &type = E.value.data_type;
|
const GDScriptDataType &type = E.value.data_type;
|
||||||
|
@ -702,6 +704,8 @@ void GDScript::_static_default_init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
void GDScript::_save_old_static_data() {
|
void GDScript::_save_old_static_data() {
|
||||||
old_static_variables_indices = static_variables_indices;
|
old_static_variables_indices = static_variables_indices;
|
||||||
old_static_variables = static_variables;
|
old_static_variables = static_variables;
|
||||||
|
@ -865,9 +869,6 @@ Error GDScript::reload(bool p_keep_state) {
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
if (can_run && p_keep_state) {
|
if (can_run && p_keep_state) {
|
||||||
_restore_old_static_data();
|
_restore_old_static_data();
|
||||||
} else if (!can_run) {
|
|
||||||
// Initialize static variables with sane default values even if the constructor isn't called.
|
|
||||||
_static_default_init();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -904,18 +905,15 @@ void GDScript::unload_static() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant GDScript::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
Variant GDScript::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||||
if (unlikely(!valid)) {
|
|
||||||
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
|
||||||
return Variant();
|
|
||||||
}
|
|
||||||
|
|
||||||
GDScript *top = this;
|
GDScript *top = this;
|
||||||
while (top) {
|
while (top) {
|
||||||
HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions.find(p_method);
|
if (likely(top->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions.find(p_method);
|
||||||
ERR_FAIL_COND_V_MSG(!E->value->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script.");
|
if (E) {
|
||||||
|
ERR_FAIL_COND_V_MSG(!E->value->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script.");
|
||||||
|
|
||||||
return E->value->call(nullptr, p_args, p_argcount, r_error);
|
return E->value->call(nullptr, p_args, p_argcount, r_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
top = top->_base;
|
top = top->_base;
|
||||||
}
|
}
|
||||||
|
@ -931,10 +929,6 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const GDScript *top = this;
|
const GDScript *top = this;
|
||||||
while (top) {
|
while (top) {
|
||||||
{
|
{
|
||||||
|
@ -948,7 +942,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
|
||||||
{
|
{
|
||||||
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
||||||
if (E) {
|
if (E) {
|
||||||
if (E->value.getter) {
|
if (likely(top->valid) && E->value.getter) {
|
||||||
Callable::CallError ce;
|
Callable::CallError ce;
|
||||||
r_ret = const_cast<GDScript *>(this)->callp(E->value.getter, nullptr, 0, ce);
|
r_ret = const_cast<GDScript *>(this)->callp(E->value.getter, nullptr, 0, ce);
|
||||||
return true;
|
return true;
|
||||||
|
@ -958,7 +952,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (likely(top->valid)) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = top->member_functions.find(p_name);
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = top->member_functions.find(p_name);
|
||||||
if (E && E->value->is_static()) {
|
if (E && E->value->is_static()) {
|
||||||
if (top->rpc_config.has(p_name)) {
|
if (top->rpc_config.has(p_name)) {
|
||||||
|
@ -991,10 +985,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GDScript *top = this;
|
GDScript *top = this;
|
||||||
while (top) {
|
while (top) {
|
||||||
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
||||||
|
@ -1009,7 +999,7 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (member->setter) {
|
if (likely(top->valid) && member->setter) {
|
||||||
const Variant *args = &value;
|
const Variant *args = &value;
|
||||||
Callable::CallError err;
|
Callable::CallError err;
|
||||||
callp(member->setter, &args, 1, err);
|
callp(member->setter, &args, 1, err);
|
||||||
|
@ -1029,10 +1019,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const {
|
void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const {
|
||||||
p_properties->push_back(PropertyInfo(Variant::STRING, "script/source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
p_properties->push_back(PropertyInfo(Variant::STRING, "script/source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||||
|
|
||||||
if (unlikely(!valid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<const GDScript *> classes;
|
List<const GDScript *> classes;
|
||||||
const GDScript *top = this;
|
const GDScript *top = this;
|
||||||
while (top) {
|
while (top) {
|
||||||
|
@ -1649,10 +1635,6 @@ GDScript::~GDScript() {
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
|
||||||
bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
HashMap<StringName, GDScript::MemberInfo>::Iterator E = script->member_indices.find(p_name);
|
HashMap<StringName, GDScript::MemberInfo>::Iterator E = script->member_indices.find(p_name);
|
||||||
if (E) {
|
if (E) {
|
||||||
|
@ -1666,7 +1648,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (member->setter) {
|
if (likely(script->valid) && member->setter) {
|
||||||
const Variant *args = &value;
|
const Variant *args = &value;
|
||||||
Callable::CallError err;
|
Callable::CallError err;
|
||||||
callp(member->setter, &args, 1, err);
|
callp(member->setter, &args, 1, err);
|
||||||
|
@ -1693,7 +1675,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (member->setter) {
|
if (likely(sptr->valid) && member->setter) {
|
||||||
const Variant *args = &value;
|
const Variant *args = &value;
|
||||||
Callable::CallError err;
|
Callable::CallError err;
|
||||||
callp(member->setter, &args, 1, err);
|
callp(member->setter, &args, 1, err);
|
||||||
|
@ -1705,7 +1687,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (likely(sptr->valid)) {
|
||||||
HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set);
|
HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set);
|
||||||
if (E) {
|
if (E) {
|
||||||
Variant name = p_name;
|
Variant name = p_name;
|
||||||
|
@ -1726,14 +1708,10 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
|
bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = script->member_indices.find(p_name);
|
HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = script->member_indices.find(p_name);
|
||||||
if (E) {
|
if (E) {
|
||||||
if (E->value.getter) {
|
if (likely(script->valid) && E->value.getter) {
|
||||||
Callable::CallError err;
|
Callable::CallError err;
|
||||||
r_ret = const_cast<GDScriptInstance *>(this)->callp(E->value.getter, nullptr, 0, err);
|
r_ret = const_cast<GDScriptInstance *>(this)->callp(E->value.getter, nullptr, 0, err);
|
||||||
if (err.error == Callable::CallError::CALL_OK) {
|
if (err.error == Callable::CallError::CALL_OK) {
|
||||||
|
@ -1758,7 +1736,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
|
||||||
{
|
{
|
||||||
HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = sptr->static_variables_indices.find(p_name);
|
HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = sptr->static_variables_indices.find(p_name);
|
||||||
if (E) {
|
if (E) {
|
||||||
if (E->value.getter) {
|
if (likely(sptr->valid) && E->value.getter) {
|
||||||
Callable::CallError ce;
|
Callable::CallError ce;
|
||||||
r_ret = const_cast<GDScript *>(sptr)->callp(E->value.getter, nullptr, 0, ce);
|
r_ret = const_cast<GDScript *>(sptr)->callp(E->value.getter, nullptr, 0, ce);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1776,7 +1754,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (likely(sptr->valid)) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(p_name);
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(p_name);
|
||||||
if (E) {
|
if (E) {
|
||||||
if (sptr->rpc_config.has(p_name)) {
|
if (sptr->rpc_config.has(p_name)) {
|
||||||
|
@ -1796,7 +1774,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (likely(sptr->valid)) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get);
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get);
|
||||||
if (E) {
|
if (E) {
|
||||||
Variant name = p_name;
|
Variant name = p_name;
|
||||||
|
@ -1836,13 +1814,15 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
|
||||||
|
|
||||||
const GDScript *sptr = script.ptr();
|
const GDScript *sptr = script.ptr();
|
||||||
while (sptr) {
|
while (sptr) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property);
|
if (likely(sptr->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property);
|
||||||
Callable::CallError err;
|
if (E) {
|
||||||
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
Callable::CallError err;
|
||||||
if (err.error == Callable::CallError::CALL_OK) {
|
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
||||||
p_property = PropertyInfo::from_dict(property);
|
if (err.error == Callable::CallError::CALL_OK) {
|
||||||
return;
|
p_property = PropertyInfo::from_dict(property);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sptr = sptr->_base;
|
sptr = sptr->_base;
|
||||||
|
@ -1850,49 +1830,47 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
|
void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// exported members, not done yet!
|
// exported members, not done yet!
|
||||||
|
|
||||||
const GDScript *sptr = script.ptr();
|
const GDScript *sptr = script.ptr();
|
||||||
List<PropertyInfo> props;
|
List<PropertyInfo> props;
|
||||||
|
|
||||||
while (sptr) {
|
while (sptr) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list);
|
if (likely(sptr->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list);
|
||||||
Callable::CallError err;
|
if (E) {
|
||||||
Variant ret = const_cast<GDScriptFunction *>(E->value)->call(const_cast<GDScriptInstance *>(this), nullptr, 0, err);
|
Callable::CallError err;
|
||||||
if (err.error == Callable::CallError::CALL_OK) {
|
Variant ret = const_cast<GDScriptFunction *>(E->value)->call(const_cast<GDScriptInstance *>(this), nullptr, 0, err);
|
||||||
ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries.");
|
if (err.error == Callable::CallError::CALL_OK) {
|
||||||
|
ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries.");
|
||||||
|
|
||||||
Array arr = ret;
|
Array arr = ret;
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
Dictionary d = arr[i];
|
Dictionary d = arr[i];
|
||||||
ERR_CONTINUE(!d.has("name"));
|
ERR_CONTINUE(!d.has("name"));
|
||||||
ERR_CONTINUE(!d.has("type"));
|
ERR_CONTINUE(!d.has("type"));
|
||||||
|
|
||||||
PropertyInfo pinfo;
|
PropertyInfo pinfo;
|
||||||
pinfo.name = d["name"];
|
pinfo.name = d["name"];
|
||||||
pinfo.type = Variant::Type(d["type"].operator int());
|
pinfo.type = Variant::Type(d["type"].operator int());
|
||||||
if (d.has("hint")) {
|
if (d.has("hint")) {
|
||||||
pinfo.hint = PropertyHint(d["hint"].operator int());
|
pinfo.hint = PropertyHint(d["hint"].operator int());
|
||||||
}
|
}
|
||||||
if (d.has("hint_string")) {
|
if (d.has("hint_string")) {
|
||||||
pinfo.hint_string = d["hint_string"];
|
pinfo.hint_string = d["hint_string"];
|
||||||
}
|
}
|
||||||
if (d.has("usage")) {
|
if (d.has("usage")) {
|
||||||
pinfo.usage = d["usage"];
|
pinfo.usage = d["usage"];
|
||||||
}
|
}
|
||||||
if (d.has("class_name")) {
|
if (d.has("class_name")) {
|
||||||
pinfo.class_name = d["class_name"];
|
pinfo.class_name = d["class_name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_CONTINUE(pinfo.name.is_empty() && (pinfo.usage & PROPERTY_USAGE_STORAGE));
|
ERR_CONTINUE(pinfo.name.is_empty() && (pinfo.usage & PROPERTY_USAGE_STORAGE));
|
||||||
ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
|
ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
|
||||||
|
|
||||||
props.push_back(pinfo);
|
props.push_back(pinfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1932,21 +1910,19 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Variant name = p_name;
|
Variant name = p_name;
|
||||||
const Variant *args[1] = { &name };
|
const Variant *args[1] = { &name };
|
||||||
|
|
||||||
const GDScript *sptr = script.ptr();
|
const GDScript *sptr = script.ptr();
|
||||||
while (sptr) {
|
while (sptr) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_can_revert);
|
if (likely(sptr->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_can_revert);
|
||||||
Callable::CallError err;
|
if (E) {
|
||||||
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
Callable::CallError err;
|
||||||
if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) {
|
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
||||||
return true;
|
if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sptr = sptr->_base;
|
sptr = sptr->_base;
|
||||||
|
@ -1956,22 +1932,20 @@ bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GDScriptInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const {
|
bool GDScriptInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Variant name = p_name;
|
Variant name = p_name;
|
||||||
const Variant *args[1] = { &name };
|
const Variant *args[1] = { &name };
|
||||||
|
|
||||||
const GDScript *sptr = script.ptr();
|
const GDScript *sptr = script.ptr();
|
||||||
while (sptr) {
|
while (sptr) {
|
||||||
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_get_revert);
|
if (likely(sptr->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_get_revert);
|
||||||
Callable::CallError err;
|
if (E) {
|
||||||
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
Callable::CallError err;
|
||||||
if (err.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) {
|
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
|
||||||
r_ret = ret;
|
if (err.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) {
|
||||||
return true;
|
r_ret = ret;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sptr = sptr->_base;
|
sptr = sptr->_base;
|
||||||
|
@ -2027,30 +2001,28 @@ void GDScriptInstance::_call_implicit_ready_recursively(GDScript *p_script) {
|
||||||
if (p_script->_base) {
|
if (p_script->_base) {
|
||||||
_call_implicit_ready_recursively(p_script->_base);
|
_call_implicit_ready_recursively(p_script->_base);
|
||||||
}
|
}
|
||||||
if (p_script->implicit_ready) {
|
if (likely(p_script->valid) && p_script->implicit_ready) {
|
||||||
Callable::CallError err;
|
Callable::CallError err;
|
||||||
p_script->implicit_ready->call(this, nullptr, 0, err);
|
p_script->implicit_ready->call(this, nullptr, 0, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant GDScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
Variant GDScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||||
if (unlikely(!script->valid)) {
|
|
||||||
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
|
||||||
return Variant();
|
|
||||||
}
|
|
||||||
|
|
||||||
GDScript *sptr = script.ptr();
|
GDScript *sptr = script.ptr();
|
||||||
if (unlikely(p_method == SceneStringName(_ready))) {
|
if (unlikely(p_method == SceneStringName(_ready))) {
|
||||||
// Call implicit ready first, including for the super classes recursively.
|
// Call implicit ready first, including for the super classes recursively.
|
||||||
_call_implicit_ready_recursively(sptr);
|
_call_implicit_ready_recursively(sptr);
|
||||||
}
|
}
|
||||||
while (sptr) {
|
while (sptr) {
|
||||||
HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(p_method);
|
if (likely(sptr->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(p_method);
|
||||||
return E->value->call(this, p_args, p_argcount, r_error);
|
if (E) {
|
||||||
|
return E->value->call(this, p_args, p_argcount, r_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sptr = sptr->_base;
|
sptr = sptr->_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
||||||
return Variant();
|
return Variant();
|
||||||
}
|
}
|
||||||
|
@ -2075,12 +2047,14 @@ void GDScriptInstance::notification(int p_notification, bool p_reversed) {
|
||||||
sptr = sptr->_base;
|
sptr = sptr->_base;
|
||||||
}
|
}
|
||||||
for (GDScript *sc : pl) {
|
for (GDScript *sc : pl) {
|
||||||
HashMap<StringName, GDScriptFunction *>::Iterator E = sc->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification);
|
if (likely(sc->valid)) {
|
||||||
if (E) {
|
HashMap<StringName, GDScriptFunction *>::Iterator E = sc->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification);
|
||||||
Callable::CallError err;
|
if (E) {
|
||||||
E->value->call(this, args, 1, err);
|
Callable::CallError err;
|
||||||
if (err.error != Callable::CallError::CALL_OK) {
|
E->value->call(this, args, 1, err);
|
||||||
//print error about notification call
|
if (err.error != Callable::CallError::CALL_OK) {
|
||||||
|
//print error about notification call
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,9 +169,7 @@ private:
|
||||||
GDScriptFunction *static_initializer = nullptr;
|
GDScriptFunction *static_initializer = nullptr;
|
||||||
|
|
||||||
Error _static_init();
|
Error _static_init();
|
||||||
#ifdef TOOLS_ENABLED
|
|
||||||
void _static_default_init(); // Initialize static variables with default values based on their types.
|
void _static_default_init(); // Initialize static variables with default values based on their types.
|
||||||
#endif
|
|
||||||
|
|
||||||
int subclass_count = 0;
|
int subclass_count = 0;
|
||||||
RBSet<Object *> instances;
|
RBSet<Object *> instances;
|
||||||
|
|
|
@ -91,12 +91,8 @@ Error GDScriptParserRef::raise_status(Status p_new_status) {
|
||||||
result = get_analyzer()->resolve_interface();
|
result = get_analyzer()->resolve_interface();
|
||||||
} break;
|
} break;
|
||||||
case INTERFACE_SOLVED: {
|
case INTERFACE_SOLVED: {
|
||||||
status = BODY_SOLVED;
|
|
||||||
result = get_analyzer()->resolve_body();
|
|
||||||
} break;
|
|
||||||
case BODY_SOLVED: {
|
|
||||||
status = FULLY_SOLVED;
|
status = FULLY_SOLVED;
|
||||||
result = get_analyzer()->resolve_dependencies();
|
result = get_analyzer()->resolve_body();
|
||||||
} break;
|
} break;
|
||||||
case FULLY_SOLVED: {
|
case FULLY_SOLVED: {
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -48,7 +48,6 @@ public:
|
||||||
PARSED,
|
PARSED,
|
||||||
INHERITANCE_SOLVED,
|
INHERITANCE_SOLVED,
|
||||||
INTERFACE_SOLVED,
|
INTERFACE_SOLVED,
|
||||||
BODY_SOLVED,
|
|
||||||
FULLY_SOLVED,
|
FULLY_SOLVED,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3006,6 +3006,8 @@ Error GDScriptCompiler::_compile_class(GDScript *p_script, const GDScriptParser:
|
||||||
has_static_data = has_static_data || inner_class->has_static_data;
|
has_static_data = has_static_data || inner_class->has_static_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p_script->_static_default_init();
|
||||||
|
|
||||||
p_script->valid = true;
|
p_script->valid = true;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -3228,11 +3230,7 @@ Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_scri
|
||||||
GDScriptCache::add_static_script(p_script);
|
GDScriptCache::add_static_script(p_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = GDScriptCache::finish_compiling(main_script->path);
|
return GDScriptCache::finish_compiling(main_script->path);
|
||||||
if (err) {
|
|
||||||
main_script->valid = false;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String GDScriptCompiler::get_error() const {
|
String GDScriptCompiler::get_error() const {
|
||||||
|
|
Loading…
Reference in New Issue