summaryrefslogtreecommitdiff
path: root/modules/mono/glue
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2020-01-02 13:54:16 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2020-01-02 13:54:20 +0100
commit844a8d215b1fa768440d5233c532f6e71c54fc14 (patch)
treeeae988c1ae1d36466f5ceca09e0eee57e62bb8d8 /modules/mono/glue
parentea75ea50d2b0f76c44e02e6fd8a558788cc375f6 (diff)
Mono/C#: Make 'GD.Print' and its variants fallback to 'ToString()'
Up until now, 'GD.Print' would convert parameters first to Variant and only then to String. This meant parameters that cannot be converted to Variant would be printed as "Null". This commit makes 'GD.Print' fallback to 'System.Object.ToString()' if the parameter could not be converted to Variant. The same applies to all 'GD.Print' variants: 'GD.PrintS', 'GD.PrintT', 'GD.PrintErr' and 'GD.PrintRaw'.
Diffstat (limited to 'modules/mono/glue')
-rw-r--r--modules/mono/glue/gd_glue.cpp96
1 files changed, 81 insertions, 15 deletions
diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp
index 041d29c7bf..9bea625450 100644
--- a/modules/mono/glue/gd_glue.cpp
+++ b/modules/mono/glue/gd_glue.cpp
@@ -71,48 +71,114 @@ MonoObject *godot_icall_GD_instance_from_id(uint64_t p_instance_id) {
}
void godot_icall_GD_print(MonoArray *p_what) {
- Array what = GDMonoMarshal::mono_array_to_Array(p_what);
String str;
- for (int i = 0; i < what.size(); i++)
- str += what[i].operator String();
+ int length = mono_array_length(p_what);
+
+ for (int i = 0; i < length; i++) {
+ MonoObject *elem = mono_array_get(p_what, MonoObject *, i);
+
+ MonoException *exc = NULL;
+ String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc);
+
+ if (exc) {
+ GDMonoUtils::set_pending_exception(exc);
+ return;
+ }
+
+ str += elem_str;
+ }
+
print_line(str);
}
void godot_icall_GD_printerr(MonoArray *p_what) {
- Array what = GDMonoMarshal::mono_array_to_Array(p_what);
+
String str;
- for (int i = 0; i < what.size(); i++)
- str += what[i].operator String();
+ int length = mono_array_length(p_what);
+
+ for (int i = 0; i < length; i++) {
+ MonoObject *elem = mono_array_get(p_what, MonoObject *, i);
+
+ MonoException *exc = NULL;
+ String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc);
+
+ if (exc) {
+ GDMonoUtils::set_pending_exception(exc);
+ return;
+ }
+
+ str += elem_str;
+ }
+
print_error(str);
}
void godot_icall_GD_printraw(MonoArray *p_what) {
- Array what = GDMonoMarshal::mono_array_to_Array(p_what);
String str;
- for (int i = 0; i < what.size(); i++)
- str += what[i].operator String();
+ int length = mono_array_length(p_what);
+
+ for (int i = 0; i < length; i++) {
+ MonoObject *elem = mono_array_get(p_what, MonoObject *, i);
+
+ MonoException *exc = NULL;
+ String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc);
+
+ if (exc) {
+ GDMonoUtils::set_pending_exception(exc);
+ return;
+ }
+
+ str += elem_str;
+ }
+
OS::get_singleton()->print("%s", str.utf8().get_data());
}
void godot_icall_GD_prints(MonoArray *p_what) {
- Array what = GDMonoMarshal::mono_array_to_Array(p_what);
String str;
- for (int i = 0; i < what.size(); i++) {
+ int length = mono_array_length(p_what);
+
+ for (int i = 0; i < length; i++) {
+ MonoObject *elem = mono_array_get(p_what, MonoObject *, i);
+
+ MonoException *exc = NULL;
+ String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc);
+
+ if (exc) {
+ GDMonoUtils::set_pending_exception(exc);
+ return;
+ }
+
if (i)
str += " ";
- str += what[i].operator String();
+
+ str += elem_str;
}
+
print_line(str);
}
void godot_icall_GD_printt(MonoArray *p_what) {
- Array what = GDMonoMarshal::mono_array_to_Array(p_what);
String str;
- for (int i = 0; i < what.size(); i++) {
+ int length = mono_array_length(p_what);
+
+ for (int i = 0; i < length; i++) {
+ MonoObject *elem = mono_array_get(p_what, MonoObject *, i);
+
+ MonoException *exc = NULL;
+ String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc);
+
+ if (exc) {
+ GDMonoUtils::set_pending_exception(exc);
+ return;
+ }
+
if (i)
str += "\t";
- str += what[i].operator String();
+
+ str += elem_str;
}
+
print_line(str);
}