Skip to content

Commit d1a9c47

Browse files
committed
Fix classes without _to_string() always returning "[Wrapped:0]"
1 parent 08fd033 commit d1a9c47

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

binding_generator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,11 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
17231723
result.append(f"\t~{class_name}();")
17241724
result.append("")
17251725

1726+
if class_name == "Object":
1727+
result.append(
1728+
'\tString _to_string() const { return "[" + String(get_class()) + ":" + itos(get_instance_id()) + "]"; }'
1729+
)
1730+
17261731
result.append("public:")
17271732

17281733
# Special cases.

include/godot_cpp/classes/wrapped.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Wrapped {
9393
bool _property_can_revert(const StringName &p_name) const { return false; }
9494
bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return false; }
9595
void _validate_property(PropertyInfo &p_property) const {}
96-
String _to_string() const { return "[" + String(get_class_static()) + ":" + itos(get_instance_id()) + "]"; }
96+
String _to_string() const { return "[Wrapped:0]"; }
9797

9898
static void notification_bind(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) {}
9999
static GDExtensionBool set_bind(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value) { return false; }
@@ -121,10 +121,6 @@ class Wrapped {
121121
return string_name;
122122
}
123123

124-
uint64_t get_instance_id() const {
125-
return 0;
126-
}
127-
128124
// Must be public but you should not touch this.
129125
GodotObject *_owner = nullptr;
130126
};

test/project/main.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ func _ready():
1818

1919
# To string.
2020
assert_equal(example.to_string(),'[ GDExtension::Example <--> Instance ID:%s ]' % example.get_instance_id())
21-
# It appears there's a bug with instance ids :-(
22-
#assert_equal($Example/ExampleMin.to_string(), 'ExampleMin:[Wrapped:%s]' % $Example/ExampleMin.get_instance_id())
21+
assert_equal($Example/ExampleMin.to_string(), '[ExampleMin:%s]' % $Example/ExampleMin.get_instance_id())
2322

2423
# Call static methods.
2524
assert_equal(Example.test_static(9, 100), 109);

0 commit comments

Comments
 (0)