BC3 - is a repository which contains a bunch of automatically generated bindings, powered by bindgen.c3l.
To install bindings for library foo, simply copy foo.c3l located in libs to your project and set foo as dependenncy.
First of all, install libclang required by bindgen.c3l, then simply run c3c run glfw as an examples. The following bindings are currently supported:
- GLFW
- Vulkan
- LLVM (Nearly complete)
- Python (Mostly incomplete)
For that you need to do 3 steps:
- Add required headers (and dependent headers also) to
headersdirectory - Create
libs/yourlib.c3ldirectory with accordingmanifest.jsoninside of it - Create binding generator itself inside of
generators/directory. For example, to create bindings for glfw, you need to:
- Create
generators/glfw.c3 - Add target
glfwtoproject.json:
{
"targets" : {
"glfw" : {
"sources" : [ "generators/glfw.c3" ],
"type" : "executable",
},
}
}- Specify
module gen;on top ofgenerators/glfw.c3 - Write a function named the same as your created file,
glfwon our case, which takes two parameters:String srcandString out- source and output file names respectively. It must perform the generation itself. See already written bindings and look atbindgen/bindgen.c3l/bindgen.c3for provided bindgen API - Call this function inside of
generators/main.c3entry point via@generatemacro, which takes three paramters: 1st -mainarguments, 2nd - header file name (respectively toheadersdirectory) and 3rd - library name. As you can see the third parameter defines library name, function name and interface file name at the same time.
- Run
c3c run yourlibraryto check it out