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

PyRay not working for me #38

Closed Guilherme32 closed 2 years ago

Guilherme32 commented 2 years ago

Hello, I encountered a little problem when trying to use the binding. The PyRay class doesn't seem to have any of the snakecase conversions working for me. When I try to run the examples, this error is shown.

Traceback (most recent call last): File "D:/Projects/python/mapmaker/main.py", line 25, in pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, AttributeError: 'PyRay' object has no attribute 'init_window'

I ended up finding a workaroud to fix this for my situation for now. I navigated through the PyRay class definition (on pyray.py) in search of something and ended up removing the comment on line 34 to allow the program to print the name and attribute. It seems that isbuiltin is returning false to the methods that should be defined with the new name, defining them with the c convention. I just replaced the line 36:

if isbuiltin(attr):

with this one

if isbuiltin(attr) or str(type(attr)) == "\<class '_cffi_backend.__FFIFunctionWrapper'>":

As for system information, I am using windows 10, with the pypy interpreter, and I built the library from source. It's my first time reporting anything anywhere on github, so please do let me know if I need to give any extra information.

electronstudio commented 2 years ago

Seems to be a problem specific to Pypy. (Can you confirm you don't get the problem using regular CPython?) I will add your fix if you like but I haven't tested much with Pypy so there could be other issues.

Guilherme32 commented 2 years ago

I just tested on CPython and it worked fine. I think my solution looks a bit ulgy and very 'workaround like'. What people from my land would call a 'gambiarra'. If you think it is worth adding, as is or writing it in a cleaner way, feel free to. I leave the decision to you :). Either way, thanks for the attention.

Also, in a somewhat related note, my ide doesn't recognize the dinamically set attributes for the pyray class, so I built a little pyi stub and now works a bit better. Is is something worth being shared in the project?

electronstudio commented 2 years ago

Well the whole idea of dynamically modifying function calls in PyRay is a 'gambiarra' so that shouldn't be a problem.

Yes please do share your stub.