1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Optimize callable's stringify text.

This commit is contained in:
Daylily-Zeleen
2024-12-05 14:24:39 +08:00
parent 1f47e4c4e3
commit 614a51f293
3 changed files with 17 additions and 6 deletions

View File

@@ -361,9 +361,13 @@ Callable::operator String() const {
if (base) { if (base) {
String class_name = base->get_class(); String class_name = base->get_class();
Ref<Script> script = base->get_script(); Ref<Script> script = base->get_script();
if (script.is_valid() && script->get_path().is_resource_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() + ")"; class_name += "(" + script->get_path().get_file() + ")";
} }
}
return class_name + "::" + String(method); return class_name + "::" + String(method);
} else { } else {
return "null::" + String(method); return "null::" + String(method);

View File

@@ -178,12 +178,12 @@ uint32_t GDScriptLambdaSelfCallable::hash() const {
String GDScriptLambdaSelfCallable::get_as_text() const { String GDScriptLambdaSelfCallable::get_as_text() const {
if (function == nullptr) { if (function == nullptr) {
return "<invalid lambda>"; return "<invalid self lambda>";
} }
if (function->get_name() != StringName()) { 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 { 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 GDScriptRPCCallable::get_as_text() const {
String class_name = object->get_class(); String class_name = object->get_class();
Ref<Script> script = object->get_script(); 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 { CallableCustom::CompareEqualFunc GDScriptRPCCallable::get_compare_equal_func() const {