File tree 4 files changed +49
-1
lines changed
4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -1855,6 +1855,34 @@ void CSharpInstance::_call_notification(int p_notification) {
1855
1855
}
1856
1856
}
1857
1857
1858
+ String CSharpInstance::to_string (bool *r_valid) {
1859
+ MonoObject *mono_object = get_mono_object ();
1860
+
1861
+ if (mono_object == NULL ) {
1862
+ if (r_valid)
1863
+ *r_valid = false ;
1864
+ return String ();
1865
+ }
1866
+
1867
+ MonoException *exc = NULL ;
1868
+ MonoString *result = GDMonoUtils::object_to_string (mono_object, &exc);
1869
+
1870
+ if (exc) {
1871
+ GDMonoUtils::set_pending_exception (exc);
1872
+ if (r_valid)
1873
+ *r_valid = false ;
1874
+ return String ();
1875
+ }
1876
+
1877
+ if (result == NULL ) {
1878
+ if (r_valid)
1879
+ *r_valid = false ;
1880
+ return String ();
1881
+ }
1882
+
1883
+ return GDMonoMarshal::mono_string_to_godot (result);
1884
+ }
1885
+
1858
1886
Ref<Script> CSharpInstance::get_script () const {
1859
1887
1860
1888
return script;
Original file line number Diff line number Diff line change @@ -261,6 +261,8 @@ class CSharpInstance : public ScriptInstance {
261
261
virtual void notification (int p_notification);
262
262
void _call_notification (int p_notification);
263
263
264
+ virtual String to_string (bool *r_valid);
265
+
264
266
virtual Ref<Script> get_script () const ;
265
267
266
268
virtual ScriptLanguage *get_language ();
Original file line number Diff line number Diff line change @@ -2300,9 +2300,14 @@ void BindingsGenerator::_populate_object_type_interfaces() {
2300
2300
if (method_info.name .empty ())
2301
2301
continue ;
2302
2302
2303
+ String cname = method_info.name ;
2304
+
2305
+ if (blacklisted_methods.find (itype.cname ) && blacklisted_methods[itype.cname ].find (cname))
2306
+ continue ;
2307
+
2303
2308
MethodInterface imethod;
2304
2309
imethod.name = method_info.name ;
2305
- imethod.cname = imethod. name ;
2310
+ imethod.cname = cname ;
2306
2311
2307
2312
if (method_info.flags & METHOD_FLAG_VIRTUAL)
2308
2313
imethod.is_virtual = true ;
@@ -2975,6 +2980,13 @@ void BindingsGenerator::_populate_global_constants() {
2975
2980
}
2976
2981
}
2977
2982
2983
+ void BindingsGenerator::_initialize_blacklisted_methods () {
2984
+
2985
+ blacklisted_methods[" Object" ].push_back (" to_string" ); // there is already ToString
2986
+ blacklisted_methods[" Object" ].push_back (" _to_string" ); // override ToString instead
2987
+ blacklisted_methods[" Object" ].push_back (" _init" ); // never called in C# (TODO: implement it)
2988
+ }
2989
+
2978
2990
void BindingsGenerator::_log (const char *p_format, ...) {
2979
2991
2980
2992
if (log_print_enabled) {
@@ -2992,6 +3004,8 @@ void BindingsGenerator::_initialize() {
2992
3004
2993
3005
enum_types.clear ();
2994
3006
3007
+ _initialize_blacklisted_methods ();
3008
+
2995
3009
_populate_object_type_interfaces ();
2996
3010
_populate_builtin_type_interfaces ();
2997
3011
Original file line number Diff line number Diff line change @@ -491,6 +491,10 @@ class BindingsGenerator {
491
491
List<InternalCall> core_custom_icalls;
492
492
List<InternalCall> editor_custom_icalls;
493
493
494
+ Map<StringName, List<StringName> > blacklisted_methods;
495
+
496
+ void _initialize_blacklisted_methods ();
497
+
494
498
struct NameCache {
495
499
StringName type_void;
496
500
StringName type_Array;
You can’t perform that action at this time.
0 commit comments