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

[Build] Initial implementation with API generation #132

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

SpaiR
Copy link
Owner

@SpaiR SpaiR commented May 27, 2022

Description

At the moment binding is created manually in Java code. And it becomes very frustrating to do, when you need to copy paste the same method 5 more times, just to implement "optional" args behaviour.

The new approach introduces an API for automatic binding generation. All is required is to provide a metadata file in a proper syntax. Stuff still need to be done manually. Yet everything becomes much easier when to implement methods with "optional" args you just need to mark those args as optional.

TODO

  • Struct fields generation
  • Enums generation
  • Convert Dear ImGui binding to the new approach (without extensions)

Since generation API mostly automates things around the old approach, they can co-exist.

Type of change

  • Minor changes or tweaks (quality of life stuff)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

@SpaiR SpaiR added the enhancement New feature or request label May 27, 2022
@tlf30
Copy link
Contributor

tlf30 commented May 30, 2022

Just saw this, looks very interesting.

@calvertdw
Copy link
Contributor

Excited for this!

@Semisol
Copy link

Semisol commented Jul 23, 2023

Wondering how this is PR is going, since I want to use some features only available on a more recent ImPlot version :)

@phraktle
Copy link

phraktle commented Jan 7, 2024

Hi @SpaiR, do you think this binding generator might be helpful? https://github.com/dearimgui/dear_bindings

@SpaiR
Copy link
Owner Author

SpaiR commented Jan 8, 2024

Hi @SpaiR, do you think this binding generator might be helpful? https://github.com/dearimgui/dear_bindings

@phraktle

Hello. This is a generator for definitions. It helps to avoid manual routines when you need to go through header files. However, for the purpose of this PR, it's useless since I've already created such a generator. I'm using clang++ and its ast-dump functionality, and I find the result more robust than those of Python scripts.

For example, this is how I extract enums:

{
    "@type" : "AstEnumDecl",
    "offset" : 121559,
    "name" : "ImGuiTreeNodeFlags_",
    "decls" : [ {
      "@type" : "AstFullComment",
      "offset" : 121495,
      "decls" : [ {
        "@type" : "AstParagraphComment",
        "offset" : 121495,
        "decls" : [ {
          "@type" : "AstTextComment",
          "offset" : 121495,
          "text" : " Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*()"
        } ]
      } ]
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121585,
      "name" : "ImGuiTreeNodeFlags_None",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 0,
      "value" : "0",
      "evaluatedValue" : "0"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121634,
      "name" : "ImGuiTreeNodeFlags_Selected",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 1,
      "value" : "1 << 0",
      "evaluatedValue" : "1"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121710,
      "name" : "ImGuiTreeNodeFlags_Framed",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 2,
      "value" : "1 << 1",
      "evaluatedValue" : "2"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121824,
      "name" : "ImGuiTreeNodeFlags_AllowItemOverlap",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 3,
      "value" : "1 << 2",
      "evaluatedValue" : "4"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121943,
      "name" : "ImGuiTreeNodeFlags_NoTreePushOnOpen",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 4,
      "value" : "1 << 3",
      "evaluatedValue" : "8"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122104,
      "name" : "ImGuiTreeNodeFlags_NoAutoOpenOnLog",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 5,
      "value" : "1 << 4",
      "evaluatedValue" : "16"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122288,
      "name" : "ImGuiTreeNodeFlags_DefaultOpen",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 6,
      "value" : "1 << 5",
      "evaluatedValue" : "32"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122371,
      "name" : "ImGuiTreeNodeFlags_OpenOnDoubleClick",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 7,
      "value" : "1 << 6",
      "evaluatedValue" : "64"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122461,
      "name" : "ImGuiTreeNodeFlags_OpenOnArrow",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 8,
      "value" : "1 << 7",
      "evaluatedValue" : "128"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122668,
      "name" : "ImGuiTreeNodeFlags_Leaf",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 9,
      "value" : "1 << 8",
      "evaluatedValue" : "256"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122790,
      "name" : "ImGuiTreeNodeFlags_Bullet",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 10,
      "value" : "1 << 9",
      "evaluatedValue" : "512"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122883,
      "name" : "ImGuiTreeNodeFlags_FramePadding",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 11,
      "value" : "1 << 10",
      "evaluatedValue" : "1024"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123101,
      "name" : "ImGuiTreeNodeFlags_SpanAvailWidth",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 12,
      "value" : "1 << 11",
      "evaluatedValue" : "2048"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123428,
      "name" : "ImGuiTreeNodeFlags_SpanFullWidth",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 13,
      "value" : "1 << 12",
      "evaluatedValue" : "4096"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123568,
      "name" : "ImGuiTreeNodeFlags_NavLeftJumpsBackHere",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 14,
      "value" : "1 << 13",
      "evaluatedValue" : "8192"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123910,
      "name" : "ImGuiTreeNodeFlags_CollapsingHeader",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 15,
      "value" : "ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog",
      "evaluatedValue" : "26"
    } ]
  }

There's no need to say that it can generate definitions for any header files, even those not related to Dear ImGui.

I understand your concerns about this PR. I, myself, am not pleased with how it is progressing. The reason for its prolonged development is time. It's hard to find the motivation to work on it in my spare time. During my working hours, I have many more responsibilities. Still, I believe the PR will be completed eventually. After that, tasks like binding updates will become a routine thing.

At the moment, I've fully covered the function generation for the main ImGui class. Now, I need to do the same for struct fields.

@phraktle
Copy link

phraktle commented Jan 9, 2024

Hi @SpaiR, I have increased my monthly contribution to the project, as I find it very useful and would love to see it evolve! Your work is much appreciated.

I would encourage others to show their appreciation as well – even a little goes a long way in motivation: https://ko-fi.com/spair

@calvertdw
Copy link
Contributor

We believe in you! 😄

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

Successfully merging this pull request may close these issues.

None yet

5 participants