Browse Source

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

Optimize callable's stringify text.
Thaddeus Crews 8 months ago
parent
commit
9c290c4c56

+ 6 - 2
core/variant/callable.cpp

@@ -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 {

+ 3 - 3
modules/gdscript/gdscript_lambda_callable.cpp

@@ -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 {

+ 8 - 1
modules/gdscript/gdscript_rpc_callable.cpp

@@ -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 {