Hi
I would like to start a discussion on the way the code for the micropython bindings are generated.
The reason why I would to do that is that I’m in the middle of generating bindings for cpython and I would like to have the interface 100% same if possible (and I think it should be possible).
I see that I replicated a lot of work that is also done during the code generation for the micropython bindings.
One of the biggest challenges is parsing the c source code and extract the information need to generate the bindings.
I looked at the tool used to generate the micropython bindings and unfortunately the extraction/information gathering part is partly done during the code generation itself.
So it is currently not easy to just use the extraction and branch off into a different code generation system for cpython.
What would like to see is that the code generation is splitted into two different tools:
- Parse the lvgl sources and gather all the information about objects/structs/global functions and store them in an intermediate file
- Use that “database” generate by the first tool and generate the binding code
We could use this “database” also to generate bindings for other languages (C++, rust, …) and ensure that way that the API is as similar as possible across all languages.
Another topic would be to enhance the interface by for example adding default values for parameters for languages which have support for it (for example the user_data parameter for event bindings)
Unfortunately I have not found a way to annotate that in the lvgl source file and have a parser be able to extract the information directly from the source. But maybe somebody has an idea how to achieve that.
Also, I think we should discuss how an object oriented API should look like.
For example, the micropython bindings expose the color creation functions as global functions:
lv.color_hex (0x123)
In my binding generation these function would be class functions of the color class:
lv.color.hex (0x123)
I’m not sure what’s the better approach, but it definitely needs discussion.
I’m also convinced once we split the parsing and the code generation it will be easier to find people willing to assist in the code generation part because currently that is so deeply interconnected that people get scared to touch the code.
So, what are your though on that?
I’m looking forward to get some feedback…
Thanks a lot in advance,
martin