3.0 - Simple IHandle interface for XYZHandle structs - #2504
Conversation
|
|
||
| namespace Silk.NET.Core; | ||
|
|
||
| public interface IHandle |
There was a problem hiding this comment.
Missing docs comments are resulting in compilation failure.
| CastExpression(IdentifierName("IntPtr"), IdentifierName("Handle")), | ||
| LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)) |
There was a problem hiding this comment.
Could we do this == default to make it agnostic to non-pointer-sized handles?
|
|
||
| namespace Silk.NET.Core; | ||
|
|
||
| public interface IHandle |
There was a problem hiding this comment.
Hmmm on second thought, maybe we could do IHandle<TSelf> : IEquatable<TSelf>, IEqualityOperators<TSelf, TSelf, bool>? At this point we totally negate the need for IsNull as users generalising over T: IHandle<T>>? Could maybe keep this non-generic interface and DIM it in the generic one if we want (is that a thing?) If we go that route no changes will be required to TransformHandles other than the base list.
There was a problem hiding this comment.
I recently worked on some unofficial HarfBuzz bindings using Silk 3 and HarfBuzz uses a null object pattern, which can be exposed as an IsNullOrEmpty(IHarfBuzz) or IsEmpty(IHarfBuzz) method on the HarfBuzz handles. This means having the IsNull property would be nice for consistency.
To be clear, not asking for the methods to be added to the IHandle interface. There likely will need to be a HarfBuzz-specific handle interface.
https://harfbuzz.github.io/object-model-lifecycle.html
Finally, object constructors (and, indeed, as much of the shaping API as possible) will never return NULL. Instead, if there is an allocation error, each constructor will return an “empty” object singleton.
HarfBuzz exposes these "empty" singletons as *GetEmpty() functions:

This matters more if we ever add HarfBuzz bindings officially to Silk, but does represent a potential edge case.
Also, open to having both the equality interfaces and the property/methods, but I have to give it some more thought.
|
Is this still being worked on? |
Summary of the PR
Adds a simple IHandle struct for XYZHandle structs, and implements an
IsNullproperty.Related issues, Discord discussions, or proposals
https://discord.com/channels/521092042781229087/587346162802229298/1443561471245291592
Further Comments
Only tested locally with SDL.