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

Overrides? #3

Open
marler8997 opened this issue May 29, 2021 · 1 comment
Open

Overrides? #3

marler8997 opened this issue May 29, 2021 · 1 comment

Comments

@marler8997
Copy link
Collaborator

marler8997 commented May 29, 2021

daurnimator asked if zigwin32 had the ability to override types. He suggested the root module could do something like this:

pub const zigwin32_config = struct {
    pub const overrides = struct {
        pub const SOME_STRUCT = struct{....}
    };
};

To support this, whenever I generate a type, instead of this:

pub const SOME_STRUCT = struct {
    //...
};

I could do something like this:

pub const SOME_STRUCT = if (getOverride("SOME_STRUCT")) |o| o else struct {
    //...
};

Where getOverride would look something like:

pub fn getOverride(comptime sym: []const u8) ?type {
    const root = @import("root");
    if (@hasDecl(root, "zigwin32_config")) {
        if (@hasDecl(root.zigwin32_config, "override")) {
            if (@hasDecl(root.zigwin32_config.override, sym)) {
                return @field(root.zigwin32_config.override, sym);
            }
        }
    }
    return null;
}

Note that this mechanism could be leveraged to help with a solution to the std interop problem.

@daurnimator
Copy link

if (getOverride("SOME_STRUCT")) |o| o else struct {

getOverride("SOME_STRUCT") orelse struct {....

Note also that overrides would follow the same structures you have, e.g.

pub const zigwin32_config = struct {
    pub const overrides = struct {
        pub const ai = struct {
          pub const FOO = struct{....}
        }
        pub const otherthing = struct {
          pub const BAR = struct{....}
        }
        pub const core = struct {
          pub const HANDLE = std.os.windows.HANDLE;
        }
    };
};

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

2 participants