Skip to content

Automatically generate pkpy<=>c bindings (cpp+pyi) with raylib's JSON format

License

Notifications You must be signed in to change notification settings

pocketpy/raylib-bindings

Repository files navigation

raylib-bindings

This repo contains a python package pkpy_bindings that can be used to generate bindings for C libraries for pocketpy. It uses raylib's JSON format for describing the API, which is generated by raylib's parser.

Current raylib version: 5.1-dev

Requirements

  • Python 3.8 or higher

Generate raylib's bindings

python build.py

This generates two files:

You can take these two files directly into your project. They are ready to use.

What build.py looks like

from pkpy_bindings import generate

pyi_path = 'output/typings/raylib.pyi'
cpp_path = 'output/raylibw.cpp'

generate(
    'raylib/parser/output/raylib_api.json',
    module_name='raylib',
    headers=['raylib.h'],
    ignored_functions=IGNORED_FUNCTIONS,
    vector_pattern=r'\bVector(\d)\b',
    opaque_structs=['rAudioBuffer', 'rAudioProcessor']
).save(pyi_path, cpp_path)

Write a main.py file

import raylib as rl

rl.InitWindow(800, 450, "raylib [core] example - basic window")

RAYWHITE = rl.Color(34, 34, 34, 255)
LIGHTGRAY = rl.Color(200, 200, 200, 255)

while not rl.WindowShouldClose():
    rl.BeginDrawing()
    rl.ClearBackground(RAYWHITE)
    rl.DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY)
    rl.EndDrawing()

rl.CloseWindow()

Build the example

cd output
mkdir build
cd build

cmake ..
cmake --build .
Debug\raylibw_test.exe

raylibw_test.png

Limitations

  • variadic functions are not supported
  • callbacks are not supported

References

License

MIT License

About

Automatically generate pkpy<=>c bindings (cpp+pyi) with raylib's JSON format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published