Merge pull request #100033 from Daylily-Zeleen/daylily-zeleen/optimize_callable_to_string

Optimize callable's stringify text.
This commit is contained in:
Thaddeus Crews 2024-12-12 16:13:23 -06:00
commit 9c290c4c56
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
3 changed files with 17 additions and 6 deletions

View File

@ -361,8 +361,12 @@ Callable::operator String() const {
if (base) {
String class_name = base->get_class();
Ref<Script> script = base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
class_name += "(" + script->get_path().get_file() + ")";
if (script.is_valid()) {
if (!script->get_global_name().is_empty()) {
class_name += "(" + script->get_global_name() + ")";
} else if (script->get_path().is_resource_file()) {
class_name += "(" + script->get_path().get_file() + ")";
}
}
return class_name + "::" + String(method);
} else {

View File

@ -178,12 +178,12 @@ uint32_t GDScriptLambdaSelfCallable::hash() const {
String GDScriptLambdaSelfCallable::get_as_text() const {
if (function == nullptr) {
return "<invalid lambda>";
return "<invalid self lambda>";
}
if (function->get_name() != StringName()) {
return function->get_name().operator String() + "(lambda)";
return function->get_name().operator String() + "(self lambda)";
}
return "(anonymous lambda)";
return "(anonymous self lambda)";
}
CallableCustom::CompareEqualFunc GDScriptLambdaSelfCallable::get_compare_equal_func() const {

View File

@ -49,7 +49,14 @@ uint32_t GDScriptRPCCallable::hash() const {
String GDScriptRPCCallable::get_as_text() const {
String class_name = object->get_class();
Ref<Script> script = object->get_script();
return class_name + "(" + script->get_path().get_file() + ")::" + String(method) + " (rpc)";
if (script.is_valid()) {
if (!script->get_global_name().is_empty()) {
class_name += "(" + script->get_global_name() + ")";
} else if (script->get_path().is_resource_file()) {
class_name += "(" + script->get_path().get_file() + ")";
}
}
return class_name + "::" + String(method) + " (rpc)";
}
CallableCustom::CompareEqualFunc GDScriptRPCCallable::get_compare_equal_func() const {