dear-imgui.hs
dear-imgui.hs copied to clipboard
Auto-generation of bindings
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
- a newtype around
- 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.
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?
I'll also add that there's always the option pre-generate a starting point and then maintain by hand
Honestly I'm leaning towards using the headers, the cimgui
stuff seems a bit limited...
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": ""
}
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.
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 🙂
They've been around for a while, yes. Perhaps they are more mature now and it is worth taking a look again.
(Also #146)
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.
I've made the parser and now trying to get a handle on its C-based bindings and how to generate them.