-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Skip methods with pointer parameters #71535
C#: Skip methods with pointer parameters #71535
Conversation
These parameters can actually be used by casting them to the appropriate pointer type, so this should a somewhat useful implementation of that example method: public override Error _GetPacket(long rBuffer, long rBufferSize)
{
var buffer = GC.AllocateArray<byte>(1024, pinned: true);
var len = _stream.Read(buffer);
_keepAlive = buffer;
*(byte**)rBuffer = (byte*)Unsafe.AsPointer(ref buffer[0]);
*(int*)rBufferSize = len;
return default;
} If proper type information about the pointer is not available, I would make these parameters |
Are these methods available in GDScript? |
@RedworkDE I think using unsafe to make the method work is not the most intuitive so I'd rather not expose it like this. I agree that if we were to expose this a better way to do it would be to use pointers or I'm not sure if we want to expose these methods but if we do we can always do it without breaking compatibility later, the main motivation for this PR is trying to remove potentially bad API before the stable release to avoid having to break compatibility later.
@neikeq I don't think so, since GDScript doesn't support pointers. The API from the example in particular does have al alternative that is exposed so it can be used in GDScript: godot/doc/classes/MultiplayerPeerExtension.xml Lines 58 to 63 in 0ddd9c3
godot/scene/main/multiplayer_peer.h Line 116 in 9ebb3e3
Which is also generated in C#: public virtual byte[] _GetPacketScript()
{
return default;
} |
If they're not usable from GDScript, I think it's fine to skip them. Especially, if there's no target type information. Not a big fan of those methods tbh. They're a poorly designed patch for exposing more advanced stuff to GDExtension. |
Wait, this is a bit different from the obscure struct pointer thing I had in mind. This one is declared as |
There is, the |
Never mind, it is what I'd thought initially. I don't have much interest in supporting that unless there's a case where it gives a great advantage over the normal API. |
Thanks! |
Ignore methods with pointer parameters when generating the C# API. Currently these methods are generated using integer type parameters which makes them unusable.
Example of a method with pointer parameters:
MultiplayerPeerExtension::_get_packet
godot/doc/classes/MultiplayerPeerExtension.xml
Lines 44 to 51 in 0ddd9c3
This generates the following C#:
The parameters are
Variant::INT
, virtual methods currently don't have metadata so they arelong
(this is a separate issue unrelated to this PR), the important thing to notice is that these parameters are meant to be pointers because they are out parameters, the generated C# methods make them impossible to use.This breaks compat because it removes methods from the public API but I don't think anyone is using them since they don't work.
For convenience, this is the diff of the generated C# API with this PR:
diff.zip