Closed
Labels
Description
Godot version
4.2
godot-cpp version
4.2-stable
System information
macOS (but it's irrelevant)
Issue description
In the test code:
String Example::test_string_resize(String p_string) const {
int orig_len = p_string.length();
p_string.resize(orig_len + 3);
...String::length() returns an int64_t, but String::resize() only takes an int:
Error resize(int p_size);When dealing with string sizes, the type should be consistent throughout the class. In fact I would recommend creating a type for it so it's obvious when we're dealing with lengths. Something like:
using StringLen = int64_t;
StringLen length() const;
Error resize(StringLen p_size);Steps to reproduce
(It's an API bug.)
Minimal reproduction project
(It's in the test code: test/src/example.cpp - Example::test_string_resize)
Reacted by Jakub Marcowski
Reacted by A Thousand Ships
Activity
AThousandShips commentedon Dec 17, 2023
I'd say
lengthshould returninthere as well, to match the API, this is likely due to a limitation in the implementation (resizeis actually added manually in the bindings generator).String::lengthin the engine returnsint, as does the godot-cppCharStringTThe underlying data container only handles 32 bit lengths, so the change here shouldn't be in the argument, but the return type, but in either case I'd say this breaks compatibility
Generally I think this could be solved if the arguments of Variant types employed the meta data information, so it correctly conveyed the type and signedness of the arguments
dsnopek commentedon Dec 22, 2023
I agree!
Godot does set
"meta"in the JSON to"int32"or"int64"for some arguments and return types (for example,AnimatedSprite3D::set_frame()andAnimatedSprite3D::get_frame()), but it doesn't in the case ofString::length()for some reason.Perhaps it's because the variant types are handled a little differently than the
ClassDBtypes?AThousandShips commentedon Dec 22, 2023
The variant types don't get any meta at all, this also affects the documentation currently, don't know if work is being done on fixing this, it's due to a different binding methodology
dsnopek commentedon Jan 24, 2024
Fixed by PR #1357