Please consinder providing a public api file
What would you think about providing a file for public apis so that other languages can write generators that can generate code which is easier to read on that language.
For example Steam provides a json file for Steamworks-SDK.
Only having a header file either requires using generic ffi-binding-generator where the yielding code is unreadable or manually parsing header file which is not great to write or writing every binding manually which is hard to maintain.
With this file it is very easy to generate ffi-bindings and create a readable code.
Example: https://github.com/aeb-dev/steamworks_gen which generates https://github.com/aeb-dev/steamworks
How is this json file generated itself? What tools exist to create bindings from this json file? What languages does this work with?
How is this json file generated itself?
I do not know but I believe there are tools to generate such files (not limited to json)
What tools exist to create bindings from this json file?
If I understand your question correctly, the point of this json file is to be able create bindings easily. So someone writes a generator in their langauge.
Let me explain further, not all languages have tools for auto-generating corresponding bindings from header. Even if they have, the tools are so generic that the generated code is unreadable/hard to understand/hard to reason. So you feel the pressure to write bindings from scratch but that is also hard to maintain and time consuming.
For example, I wanted to have steamworks binding in dart. Dart has a tool called ffi-gen which tries(not everything is supported) to generate bindings from headers file. The generated file was so ugly that I did not even think twice about writing a generator: https://github.com/aeb-dev/steamworks_gen.
Another example in c#: https://github.com/Facepunch/Facepunch.Steamworks/blob/master/Generator/Program.cs
What languages does this work with?
What do you mean? It is a json file so any language that can parse json can write a binding generator if the language supports ffi/interop
Based on your response, these seem to be the answers to my questions.
- How is this json file generated itself?
- unknown if any tool exists to do this
- What tools exist to create bindings from this json file?
- someone needs to write this
- What languages does this work with?
- it will work with any language where someone is willing to write binding code using the json somehow
Is that all correct?
The goal for Box2D v3.0 is to make it easy to create bindings, but not to necessarily make those bindings myself (too many languages).
So in order to make this happen:
- Someone needs to write a generator that takes a few Box2D headers and generates a json file
- Someone needs to create a binding generator that consumes the json
- This whole process needs to be testable in github actions
Another question, is the json following a published schema?
Is that all correct?
Yes
The goal for Box2D v3.0 is to make it easy to create bindings, but not to necessarily make those bindings myself (too many languages).
I agree.
So in order to make this happen: 1. Someone needs to write a generator that takes a few Box2D headers and generates a json file 2. Someone needs to create a binding generator that consumes the json 3. This whole process needs to be testable in github actions
Just to be on the same page. Box2c should only care about step 1.
Another question, is the json following a published schema?
AFAIK no. By the way you do not need to make it in a json file. Maybe there are other easily consumable formats. I am not expert in this topic but I found having a separate file very useful.
If you want to give a detailed look here is the steam sdk sdk.zip
Under public/steam you can find the related steam_api.json
If you prefer, I can explain the whole process on discord. My discord username is on github profile page, you can ping me anytime
Thanks for explaining. I think this is a good idea. I just need to learn more about it.
I probably won't work on this soon (other priorities), so I'll table it for now. I may ask for more information in the future.
You are welcome. Nice to hear that!
You can also ping me for testing/creating a prototype in another language
Here's an example of another library which does that https://github.com/raysan5/raylib/tree/master/parser There is a custom "parser" taking the header file, then generating various output formats for it https://github.com/raysan5/raylib/blob/master/parser/raylib_parser.c https://github.com/raysan5/raylib/blob/master/parser/output/raylib_api.json
Using clang you can compile with -ast-dump=json which gives you everything you need, however, it's extremely noisy and could do with a bit of cleanup. -fsyntax-only helps a little bit but there's an exhausting amount of bloat to read through when first writing a generator, so a utility tool to basically get rid of everything that isn't function syntax and struct declarations is recommended.
The raylib example is good. They also have a github action that generates the json and commits it back to the repo. https://github.com/raysan5/raylib/blob/master/.github/workflows/parse.yml
I remember something similar to this in original repo but I could not find right now. Is there a file that I can consume to generate a wrapper?