Open shayded-exe opened 1 year ago
Thanks @shayded-exe for the suggestion.
I was experimenting with this before. The main problem was that wrapping a function pointer in a struct is useful for the case when using delegates for backwards compatibility before .NET 5. I was lazy so I left it wrapped.
You can take a look at the generator class with uses Roslyn to create the struct: https://github.com/bottlenoselabs/c2cs/blob/925e3ae18d223394858853e8a57d3907388ba32b/src/cs/production/C2CS.Tool/Features/WriteCodeCSharp/Domain/CodeGenerator/Handlers/FunctionPointerCodeGenerator.cs#L4
Ah, makes sense
I've switched to ImGui for now so I can make progress faster, so I'm not using this tool for now, but when I inevitably need bindings for another library I'll make a fork of this to make improvements on. I've searched around a lot and this is so far the best/easiest option for generating bindings that I've found! If I need to pick it back up I'm happy to contribute.
I'm trying to generate bindings for Nuklear.
It declares the following function pointer: https://github.com/Immediate-Mode-UI/Nuklear/blob/a14e55f536e0d582930b68b2d3cac7296bae3a25/nuklear.h#L504
This generates the following C#:
It would be nice if the TypeAlias wrapper could be eliminated and the function pointer struct were named using its declared name. Additionally, it should provide a constructor and explicit conversion operator for ease of use. Like this: