Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/terenstare/sdl_parser
Write your own SDL bindings
https://github.com/terenstare/sdl_parser
bindings python sdl2 sdl3
Last synced: 23 days ago
JSON representation
Write your own SDL bindings
- Host: GitHub
- URL: https://github.com/terenstare/sdl_parser
- Owner: TerensTare
- License: mit
- Created: 2024-06-17T23:07:30.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-28T14:20:57.000Z (6 months ago)
- Last Synced: 2024-06-28T15:44:53.668Z (6 months ago)
- Topics: bindings, python, sdl2, sdl3
- Language: Python
- Homepage:
- Size: 181 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SDL_parser
This repo contains a Python script based on tree-sitter that parses SDL headers (SDL_image, SDL_mixer and SDL_ttf supported as well) and allows you to create language bindings of your own choice from the parsed ASTs.
## Setup
To run the project you need Python>=3.10. Dependencies can be acquired with
```py
pip install -r requirements.txt
```Also, before you can run the script, you need to edit `PATH_BY_UNIT` in [setup.py](./setup.py) to choose the units you want to parse (or else the script will fail). The file contains default paths for each unit but you can edit them as you see fit. Furthermore, you can edit `SDL_ROOT` which is the common path where all your SDL headers reside, relative to the project's root. All that's left is to pick a generator and run `py sdl_parser.py gen. --=` (eg. `py sdl_parser.py gen.cpp --module="sdl.{ext}"` for C++ bindings) and have your bindings generated in `out//`.
## Supported languages
This is a list of currently supported languages:
- C++ ([example](./gen/cpp/example.cpp)) (for SDL2 use [this](./gen/cpp/example-sdl2.cpp) instead)
- C# ([example](./gen/cs/Example.cs)) (NOTE: headers must be annotated as in this [PR](https://github.com/libsdl-org/SDL/pull/9907))
- JSONIf you want to write bindings for another language, please refer to [bindings-my-way](docs/bindings-my-way.md).
## Q&A
Q: Can I use this to generate SDL2 bindings?
A: Yes, but the bindings are not of the same quality as SDL3 bindings due to some coding conventions that are not present in SDL2 code. The difference is that you need to cast SDL2 enums to their underlying type when passing to functions. Also some bitflags are not recognized as enums, but rather constants. Please compare the examples on `gen/cpp` to notice the difference.For any other questions or issues, feel free to open an issue or PR. Thank you!