dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Translation error from imgui_impl_sdl2.h to cimgui_impl_sdl2.h #71

Open dinau opened 3 weeks ago

dinau commented 3 weeks ago

It seems to fail parsing ImGui_ImplSDL2_SetGamepadMode() function,
"Unrecognised element LexToken(LPAREN,'(',43,2796)" ?

python ../../libs/dear_bindings/dear_bindings.py --backend --imconfig-path ../../libs/imgui/imconfig.h -o cimgui/cimgui_impl_sdl2 ../../libs/imgui/backends/imgui_impl_sdl2.h
Dear Bindings: parse Dear ImGui headers, convert to C and output metadata.
Parsing ../../libs/imgui/imconfig.h
Parsing ...snip...\libs\imgui\backends\imgui_impl_sdl2.h
Unrecognised element LexToken(LPAREN,'(',43,2796)
Storing unmodified DOM
Applying modifiers
Writing output to cimgui/cimgui_impl_sdl2[.h/.cpp/.json]
Done

cimgui_impl_sdl2.h generated is,

... snip ...
IMGUI_IMPL_API
void
ImGui_ImplSDL2_SetGamepadMode
#endif // #ifndef IMGUI_DISABLE
#ifdef __cplusplus
} // End of extern "C" block
#endif

This is imgui/backends/imgui_impl_sdl2.h,

...snip..
IMGUI_IMPL_API void     ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = NULL, int manual_gamepads_count = -1);

#endif // #ifndef IMGUI_DISABLE

So compiling source code using cimgui_impl_sdl2.h is failed.

ShironekoBen commented 3 weeks ago

Thanks for the report - indeed, it seems that recent versions of things have broken conversion of the SDL2 backend (and wgpu, by the looks of it).

The culprit is the struct declaration inline in ImGui_ImplSDL2_SetGamepadMode, by the looks of it - the parser doesn't properly understand that at the moment. I'll add in support for it but in the meantime if you need a quick fix that declaration is actually redundant (there's a forward-declaration of the struct earlier in the file), so if you change that line to:

IMGUI_IMPL_API void     ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, _SDL_GameController** manual_gamepads_array = NULL, int manual_gamepads_count = -1);

...then it all seems to work.

I'll update this issue again once I've got a proper fix.

Thanks again!

dinau commented 3 weeks ago

Thank you for your detail explanation. I will use your suggestion code.

ShironekoBen commented 3 weeks ago

Just as an update on this, I've pushed a new version which fixes both parsing issues, so the new code should work with an unmodified versions of ImGui again.

Thanks again, and just let me know if you spot anything else that's broken!