godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

All binding classes have `const` in their arguments, which sometimes makes them unusable

Open Zylann opened this issue 3 years ago • 3 comments

According to https://github.com/Zylann/godot_voxel/issues/357

And likely because of https://github.com/godotengine/godot-cpp/blob/63df6debdf855be083e8eb877a0b92600a228e20/binding_generator.py#L466

Forcing const on all method arguments can make some arguments unusable. In the present case I expose a virtual method receiving a Ref<T> which is supposed to be modified by the implementation (through calling its non-const methods), but it can't because of the const.

Something like this cannot be done properly until Godot actually exposes a hint per method argument saying if the object is const or not.

Zylann avatar Feb 10 '22 20:02 Zylann

Is there a suitable work-around for now? will modifying the binding_generator.py to remove the const for certain prototypes be sufficient? or could that break other things?

MadMartian avatar Feb 11 '22 18:02 MadMartian

I believe removing the const should not break anything. I'm not sure why it's there. Maybe @vnen knows

Zylann avatar Feb 11 '22 20:02 Zylann

There were some changes and now it moved here: https://github.com/godotengine/godot-cpp/blob/4d9fe6dfaaee892e9b369093c20df9fe1a2ef767/binding_generator.py#L1403

Zylann avatar Feb 20 '22 20:02 Zylann

As I described in comment https://github.com/godotengine/godot/pull/64789#issuecomment-1546853406, the real problem here is the design flaw on Ref<T>::operator->. If that issue is fixed, we are going to have correct semantics, so no further changes will be required regardless of whether the parameter is Ref<T> param or const Ref<T>& param.

saki7 avatar May 14 '23 10:05 saki7