Breush / odin-binding-generator

An Odin library to convert a C header file into an Odin binding file.
MIT License
42 stars 20 forks source link

Postfix removal is a bit too greedy #17

Closed valignatev closed 2 years ago

valignatev commented 2 years ago

Hey, thanks for the nice project, helps me a lot! I'm using it to generate bindings to xcb, and I'm using options.enumValueNameRemovePostfixes = []string{"_t"}; just like in the example generator. Unfortunately, it removes not only _t from enum values, but also just T at the end of the enum value, so that XCB_WINDOW_CLASS_INPUT_OUTPUT becomes WINDOW_CLASS_INPUT_OUTPU - note no T at the end. I've tried it on the latest master.

UPD: it's not just options.enumValueNameRemovePostfixes = []string{"_t"};, it's actually a combination of these two that bugs out:

    options.enumValueNameRemove = true;
    options.enumValueNameRemovePostfixes = []string{"_t"};

also full generator, just for reference:

package main

import "bindgen"

main :: proc() {
    options : bindgen.GeneratorOptions;

    options.functionPrefixes = []string{"xcb_"};

    options.definePrefixes = []string{"XCB_"};
    options.defineCase = bindgen.Case.Constant;

    options.pseudoTypePrefixes = []string{"xcb_"};

    options.enumValuePrefixes = []string{"XCB_"};
    options.enumValueNameRemove = true;
    options.enumValueNameRemovePostfixes = []string{"_t"};

    bindgen.generate(
        packageName = "xcb",
        foreignLibrary = "system:xcb",
        outputFile = "./examples/xcb/generated/xcb.odin",
        headerFiles = []string{"./examples/xcb/headers/xcb.h", "./examples/xcb/headers/xproto.h"},
        options = options,
    );
}
Breush commented 2 years ago

Thanks for reporting, can you confirm this is fixed with latest commit?

valignatev commented 2 years ago

Fixed, yeah, thanks!