Skip to content
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

Automatically generate macro functions #175

Open
Susko3 opened this issue Nov 17, 2024 · 0 comments
Open

Automatically generate macro functions #175

Susko3 opened this issue Nov 17, 2024 · 0 comments

Comments

@Susko3
Copy link
Member

Susko3 commented Nov 17, 2024

Currently, macro functions need to be manually updated (and added), see 2590a72.

My idea for this

The manually written C# code would be the following, placed in the usual SDL_{name}.cs file:

public static partial class SDL3
{
    [Macro]
    [return: CastFrom("int")]
    public static partial SDL_PixelType SDL_PIXELTYPE([Cast("int")] SDL_PixelFormat X);
}

This will cause the source gen to generate the following code (this may be unnecessary):

    public static partial SDL_PixelType SDL_PIXELTYPE(SDL_PixelFormat X) => (SDL_PixelType)Unsafe_SDL_PIXELTYPE((int)X);

The python script would generate this C header file and add it to ClangSharp (the file is not saved to disk/repo):

#include <SDL3/SDL.h>

//      | taken from [CastFrom("int")]
//      ↓                        ↓ taken from [Cast("int")]
inline int Unsafe_SDL_PIXELTYPE(int X)
{
    return SDL_PIXELTYPE(X);
}

ClangSharp can convert inline functions to C# code, so calling the macro functions inside inline functions should work.

The generated C# code will be horrible, as it'll resolve all macros (and SDL code sometime nests a lot of macros).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant