electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

improve handling of 'out' parameters #60

Open electronstudio opened 2 years ago

electronstudio commented 2 years ago

Not sure if Raylib uses any of these, but RayGUI certainly does. Currently to use with pyray code looks like this:

import pyray as pr

char_array = pr.ffi.new("char[20]")
pointer = pr.ffi.addressof(char_array)

pr.init_window(800, 600, "raygui")
while not pr.window_should_close():
    pr.begin_drawing()
    pr.clear_background(pr.RAYWHITE)

    pr.gui_text_input_box(pr.Rectangle(0, 0, 800, 600), "title", "message", "buttons", pointer)
    string = pr.ffi.string(char_array).decode('utf-8')
    pr.draw_text(f"Text entered: {string}", 10, 40, 10, pr.DARKGRAY)

    pr.end_drawing()
pr.close_window()

I guess the cleanest solution might be to remove those parameters entirely and replace them with tuple return values, but not sure if that can be done in automated way and I hate to special-case anything.

electronstudio commented 3 months ago

https://github.com/electronstudio/raylib-python-cffi/issues/121