|
|
|
@ -115,7 +115,7 @@ Variant GDScriptNativeClass::callp(const StringName &p_method, const Variant **p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GDScriptFunction *GDScript::_super_constructor(GDScript *p_script) {
|
|
|
|
|
if (p_script->initializer) {
|
|
|
|
|
if (likely(p_script->valid) && p_script->initializer) {
|
|
|
|
|
return p_script->initializer;
|
|
|
|
|
} else {
|
|
|
|
|
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);
|
|
|
|
|
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) {
|
|
|
|
@ -662,7 +666,7 @@ String GDScript::_get_debug_path() const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Error GDScript::_static_init() {
|
|
|
|
|
if (static_initializer) {
|
|
|
|
|
if (likely(valid) && static_initializer) {
|
|
|
|
|
Callable::CallError call_err;
|
|
|
|
|
static_initializer->call(nullptr, nullptr, 0, call_err);
|
|
|
|
|
if (call_err.error != Callable::CallError::CALL_OK) {
|
|
|
|
@ -679,8 +683,6 @@ Error GDScript::_static_init() {
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
|
|
void GDScript::_static_default_init() {
|
|
|
|
|
for (const KeyValue<StringName, MemberInfo> &E : static_variables_indices) {
|
|
|
|
|
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() {
|
|
|
|
|
old_static_variables_indices = static_variables_indices;
|
|
|
|
|
old_static_variables = static_variables;
|
|
|
|
@ -873,9 +877,6 @@ Error GDScript::reload(bool p_keep_state) {
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
if (can_run && p_keep_state) {
|
|
|
|
|
_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
|
|
|
|
|
|
|
|
|
@ -912,19 +913,16 @@ void GDScript::unload_static() const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
while (top) {
|
|
|
|
|
if (likely(top->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions.find(p_method);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
top = top->_base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -939,10 +937,6 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unlikely(!valid)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const GDScript *top = this;
|
|
|
|
|
while (top) {
|
|
|
|
|
{
|
|
|
|
@ -956,7 +950,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
|
{
|
|
|
|
|
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
|
|
|
|
if (E) {
|
|
|
|
|
if (E->value.getter) {
|
|
|
|
|
if (likely(top->valid) && E->value.getter) {
|
|
|
|
|
Callable::CallError ce;
|
|
|
|
|
r_ret = const_cast<GDScript *>(this)->callp(E->value.getter, nullptr, 0, ce);
|
|
|
|
|
return true;
|
|
|
|
@ -966,7 +960,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);
|
|
|
|
|
if (E && E->value->is_static()) {
|
|
|
|
|
if (top->rpc_config.has(p_name)) {
|
|
|
|
@ -999,10 +993,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unlikely(!valid)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GDScript *top = this;
|
|
|
|
|
while (top) {
|
|
|
|
|
HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name);
|
|
|
|
@ -1017,7 +1007,7 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (member->setter) {
|
|
|
|
|
if (likely(top->valid) && member->setter) {
|
|
|
|
|
const Variant *args = &value;
|
|
|
|
|
Callable::CallError err;
|
|
|
|
|
callp(member->setter, &args, 1, err);
|
|
|
|
@ -1037,10 +1027,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
if (unlikely(!valid)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<const GDScript *> classes;
|
|
|
|
|
const GDScript *top = this;
|
|
|
|
|
while (top) {
|
|
|
|
@ -1657,10 +1643,6 @@ GDScript::~GDScript() {
|
|
|
|
|
//////////////////////////////
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (E) {
|
|
|
|
@ -1674,7 +1656,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (member->setter) {
|
|
|
|
|
if (likely(script->valid) && member->setter) {
|
|
|
|
|
const Variant *args = &value;
|
|
|
|
|
Callable::CallError err;
|
|
|
|
|
callp(member->setter, &args, 1, err);
|
|
|
|
@ -1701,7 +1683,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (member->setter) {
|
|
|
|
|
if (likely(sptr->valid) && member->setter) {
|
|
|
|
|
const Variant *args = &value;
|
|
|
|
|
Callable::CallError err;
|
|
|
|
|
callp(member->setter, &args, 1, err);
|
|
|
|
@ -1713,7 +1695,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);
|
|
|
|
|
if (E) {
|
|
|
|
|
Variant name = p_name;
|
|
|
|
@ -1734,14 +1716,10 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (E) {
|
|
|
|
|
if (E->value.getter) {
|
|
|
|
|
if (likely(script->valid) && E->value.getter) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
|
r_ret = const_cast<GDScriptInstance *>(this)->callp(E->value.getter, nullptr, 0, err);
|
|
|
|
|
if (err.error == Callable::CallError::CALL_OK) {
|
|
|
|
@ -1766,7 +1744,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);
|
|
|
|
|
if (E) {
|
|
|
|
|
if (E->value.getter) {
|
|
|
|
|
if (likely(sptr->valid) && E->value.getter) {
|
|
|
|
|
Callable::CallError ce;
|
|
|
|
|
r_ret = const_cast<GDScript *>(sptr)->callp(E->value.getter, nullptr, 0, ce);
|
|
|
|
|
return true;
|
|
|
|
@ -1784,7 +1762,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);
|
|
|
|
|
if (E) {
|
|
|
|
|
if (sptr->rpc_config.has(p_name)) {
|
|
|
|
@ -1804,7 +1782,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);
|
|
|
|
|
if (E) {
|
|
|
|
|
Variant name = p_name;
|
|
|
|
@ -1844,6 +1822,7 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
|
|
|
|
|
|
|
|
|
|
const GDScript *sptr = script.ptr();
|
|
|
|
|
while (sptr) {
|
|
|
|
|
if (likely(sptr->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property);
|
|
|
|
|
if (E) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
@ -1853,21 +1832,19 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sptr = sptr->_base;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
|
|
|
|
|
if (unlikely(!script->valid)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// exported members, not done yet!
|
|
|
|
|
|
|
|
|
|
const GDScript *sptr = script.ptr();
|
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
|
|
|
|
|
|
while (sptr) {
|
|
|
|
|
if (likely(sptr->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list);
|
|
|
|
|
if (E) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
@ -1904,6 +1881,7 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//instance a fake script for editing the values
|
|
|
|
|
|
|
|
|
@ -1940,15 +1918,12 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
|
|
|
|
if (unlikely(!script->valid)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Variant name = p_name;
|
|
|
|
|
const Variant *args[1] = { &name };
|
|
|
|
|
|
|
|
|
|
const GDScript *sptr = script.ptr();
|
|
|
|
|
while (sptr) {
|
|
|
|
|
if (likely(sptr->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_can_revert);
|
|
|
|
|
if (E) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
@ -1957,6 +1932,7 @@ bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sptr = sptr->_base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1964,15 +1940,12 @@ bool GDScriptInstance::property_can_revert(const StringName &p_name) const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GDScriptInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
|
if (unlikely(!script->valid)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Variant name = p_name;
|
|
|
|
|
const Variant *args[1] = { &name };
|
|
|
|
|
|
|
|
|
|
const GDScript *sptr = script.ptr();
|
|
|
|
|
while (sptr) {
|
|
|
|
|
if (likely(sptr->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_get_revert);
|
|
|
|
|
if (E) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
@ -1982,6 +1955,7 @@ bool GDScriptInstance::property_get_revert(const StringName &p_name, Variant &r_
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sptr = sptr->_base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2035,30 +2009,28 @@ void GDScriptInstance::_call_implicit_ready_recursively(GDScript *p_script) {
|
|
|
|
|
if (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;
|
|
|
|
|
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) {
|
|
|
|
|
if (unlikely(!script->valid)) {
|
|
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
|
|
|
|
return Variant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GDScript *sptr = script.ptr();
|
|
|
|
|
if (unlikely(p_method == SceneStringName(_ready))) {
|
|
|
|
|
// Call implicit ready first, including for the super classes recursively.
|
|
|
|
|
_call_implicit_ready_recursively(sptr);
|
|
|
|
|
}
|
|
|
|
|
while (sptr) {
|
|
|
|
|
if (likely(sptr->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(p_method);
|
|
|
|
|
if (E) {
|
|
|
|
|
return E->value->call(this, p_args, p_argcount, r_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sptr = sptr->_base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
|
|
|
|
return Variant();
|
|
|
|
|
}
|
|
|
|
@ -2083,6 +2055,7 @@ void GDScriptInstance::notification(int p_notification, bool p_reversed) {
|
|
|
|
|
sptr = sptr->_base;
|
|
|
|
|
}
|
|
|
|
|
for (GDScript *sc : pl) {
|
|
|
|
|
if (likely(sc->valid)) {
|
|
|
|
|
HashMap<StringName, GDScriptFunction *>::Iterator E = sc->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification);
|
|
|
|
|
if (E) {
|
|
|
|
|
Callable::CallError err;
|
|
|
|
@ -2092,6 +2065,7 @@ void GDScriptInstance::notification(int p_notification, bool p_reversed) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String GDScriptInstance::to_string(bool *r_valid) {
|
|
|
|
|