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

Auto-generation of bindings #15

Open
sheaf opened this issue Jan 27, 2021 · 9 comments
Open

Auto-generation of bindings #15

sheaf opened this issue Jan 27, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@sheaf
Copy link
Contributor

sheaf commented Jan 27, 2021

I started looking at imgui.h. It's large. I don't think it's reasonable to achieve feature completeness, even less maintainability, without auto-generating at least some portion of the bindings. We could rely on cimgui, or generate directly from the headers. This would also allow easier access to different branches of ImGui, such as the docking branch which supports multi-viewport.

I haven't looked too much into it, but for cimgui here are some possible steps:

  • parse structs_and_enums and define corresponding Haskell types
    • a newtype around CInt for each enum type, with the corresponding pattern synonyms
    • ADTs for structs
  • parse typedefs_dicts and define Haskell type synonyms
  • (the hard part) parse definitions and use them to generate bindings like the ones that currently exist in the main DearImGui.hs file.
@TristanCacqueray
Copy link
Contributor

The definitions doesn't seem to contains all the imgui.h functions, for example it doesn't have SliderFloat. Should we add an extra step to also generate the user facing functions?

@ocharles
Copy link
Member

I'll also add that there's always the option pre-generate a starting point and then maintain by hand

@sheaf
Copy link
Contributor Author

sheaf commented Jan 27, 2021

Honestly I'm leaning towards using the headers, the cimgui stuff seems a bit limited...

@sheaf
Copy link
Contributor Author

sheaf commented Jan 27, 2021

The definitions doesn't seem to contains all the imgui.h functions, for example it doesn't have SliderFloat. Should we add an extra step to also generate the user facing functions?

SliderFloat seems to be included:

  "igSliderFloat": [
    {
      "args": "(const char* label,float* v,float v_min,float v_max,const char* format,ImGuiSliderFlags flags)",
      "argsT": [
        {
          "name": "label",
          "type": "const char*"
        },
        {
          "name": "v",
          "type": "float*"
        },
        {
          "name": "v_min",
          "type": "float"
        },
        {
          "name": "v_max",
          "type": "float"
        },
        {
          "name": "format",
          "type": "const char*"
        },
        {
          "name": "flags",
          "type": "ImGuiSliderFlags"
        }
      ],
      "argsoriginal": "(const char* label,float* v,float v_min,float v_max,const char* format=\"%.3f\",ImGuiSliderFlags flags=0)",
      "call_args": "(label,v,v_min,v_max,format,flags)",
      "cimguiname": "igSliderFloat",
      "defaults": {
        "flags": "0",
        "format": "\"%.3f\""
      },
      "funcname": "SliderFloat",
      "location": "imgui:511",
      "namespace": "ImGui",
      "ov_cimguiname": "igSliderFloat",
      "ret": "bool",
      "signature": "(const char*,float*,float,float,const char*,ImGuiSliderFlags)",
      "stname": ""
    }

@dpwiz
Copy link
Member

dpwiz commented Apr 16, 2021

Code generation would be of great help of course. However, the documentation will be lacking, since it is so unstructured and ad hoc in the headers.

@dpwiz dpwiz added the enhancement New feature or request label Apr 18, 2021
@alt-romes
Copy link
Contributor

alt-romes commented Jul 4, 2023

If I understood correctly, in dear-imgui's latest release (5 hours ago) they announced a new "exciting project": Dear Bindings: alternative binding generator for C and other languages.

I thought it might be relevant to this thread 🙂

@dpwiz
Copy link
Member

dpwiz commented Jul 4, 2023

They've been around for a while, yes. Perhaps they are more mature now and it is worth taking a look again.

(Also #146)

@dpwiz
Copy link
Member

dpwiz commented Jul 4, 2023

I think I can hack a package for both of the JSON formats and then we'll see how process it into Haskell code.

When the bulk is automated away, maybe it would be even worth it to have multiple packages in different styles.

@dpwiz
Copy link
Member

dpwiz commented Jul 10, 2023

I've made the parser and now trying to get a handle on its C-based bindings and how to generate them.

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

No branches or pull requests

5 participants