add pythonic wrapper, pyray

This commit is contained in:
Richard Smith 2019-05-26 20:24:57 +01:00
parent 18f3fdfe18
commit 3a8d764408
7 changed files with 113 additions and 56 deletions

View file

@ -5,4 +5,3 @@ from .helpers import *
print("RAYLIB STATIC LOADED")

50
raylib/static/pyray.py Normal file
View file

@ -0,0 +1,50 @@
from . import rl, ffi
from ..colors import *
from inspect import ismethod,getmembers,isbuiltin
import inflection
class PyRay:
def pointer(self, struct):
return ffi.addressof(struct)
pyray = PyRay()
def makefunc(a):
#print("makefunc ",a)
def func(self, *args):
modified_args = []
for arg in args:
#print(arg, type(arg))
if type(arg) == str:
encoded = arg.encode('utf-8')
modified_args.append(encoded)
else:
modified_args.append(arg)
return a(*modified_args)
return func
def makeStructHelper(struct):
def func(self, *args):
return ffi.new(f"struct {struct} *", args)[0]
return func
for name, attr in getmembers(rl):
print(name, attr)
uname = inflection.underscore(name).replace('3_d','_3d').replace('2_d','_2d')
if isbuiltin(attr):
#print(attr)
#print(dir(attr))
#print(dir(attr.__repr__))
f = makefunc(attr)
setattr(PyRay, uname, f)
#def wrap(*args):
# print("call to ",attr)
#setattr(PyRay, uname, lambda *args: print("call to ",attr))
else:
setattr(PyRay, name, attr)
for struct in ('Vector2','Vector3','Vector4','Camera2D', 'Camera3D', 'Quaternion', 'Color'):
f = makeStructHelper(struct)
setattr(PyRay, struct, f)