Skip to content

Automatically generate macro functions #175

@Susko3

Description

@Susko3

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions