This commit is contained in:
parent
84c7eff4d7
commit
2c233d47fa
2 changed files with 20 additions and 19 deletions
|
@ -14,25 +14,22 @@
|
||||||
|
|
||||||
from raylib import rl, ffi
|
from raylib import rl, ffi
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from raylib.defines import *
|
from raylib.defines import *
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print("sorry deprecated enums dont work on dynamic version")
|
print("sorry deprecated enums dont work on dynamic version")
|
||||||
|
|
||||||
|
from inspect import getmembers, isbuiltin
|
||||||
from inspect import ismethod,getmembers,isbuiltin
|
|
||||||
import inflection
|
import inflection
|
||||||
|
|
||||||
current_module = __import__(__name__)
|
current_module = __import__(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pointer(self, struct):
|
def pointer(self, struct):
|
||||||
return ffi.addressof(struct)
|
return ffi.addressof(struct)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# I'm concerned that we are doing a lot of string comparisons on every function call to detect types.
|
# I'm concerned that we are doing a lot of string comparisons on every function call to detect types.
|
||||||
# Quickest way would probably be isinstance(result, ffi._backend._CDataBase) but that class name varies
|
# Quickest way would probably be isinstance(result, ffi._backend._CDataBase) but that class name varies
|
||||||
# depending on if binding is static/dynamic
|
# depending on if binding is static/dynamic
|
||||||
|
@ -42,11 +39,11 @@ def pointer(self, struct):
|
||||||
# Another way to improve performance might be to special-case simple types before doing the string comparisons
|
# Another way to improve performance might be to special-case simple types before doing the string comparisons
|
||||||
|
|
||||||
def makefunc(a):
|
def makefunc(a):
|
||||||
#print("makefunc ",a, ffi.typeof(a).args)
|
# print("makefunc ",a, ffi.typeof(a).args)
|
||||||
def func(*args):
|
def func(*args):
|
||||||
modified_args = []
|
modified_args = []
|
||||||
for (c_arg, arg) in zip(ffi.typeof(a).args, args):
|
for (c_arg, arg) in zip(ffi.typeof(a).args, args):
|
||||||
#print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
|
# print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
|
||||||
if c_arg.kind == 'pointer':
|
if c_arg.kind == 'pointer':
|
||||||
if type(arg) == str:
|
if type(arg) == str:
|
||||||
arg = arg.encode('utf-8')
|
arg = arg.encode('utf-8')
|
||||||
|
@ -56,9 +53,9 @@ def makefunc(a):
|
||||||
arg = ffi.new("int *", arg)
|
arg = ffi.new("int *", arg)
|
||||||
elif type(arg) is float:
|
elif type(arg) is float:
|
||||||
arg = ffi.new("float *", arg)
|
arg = ffi.new("float *", arg)
|
||||||
elif str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" and "*" not in str(arg): #CPython
|
elif str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" and "*" not in str(arg): # CPython
|
||||||
arg = ffi.addressof(arg)
|
arg = ffi.addressof(arg)
|
||||||
elif str(type(arg)) == "<class '_cffi_backend._CDataBase'>" and "*" not in str(arg): #Pypy
|
elif str(type(arg)) == "<class '_cffi_backend._CDataBase'>" and "*" not in str(arg): # Pypy
|
||||||
arg = ffi.addressof(arg)
|
arg = ffi.addressof(arg)
|
||||||
elif arg is None:
|
elif arg is None:
|
||||||
arg = ffi.NULL
|
arg = ffi.NULL
|
||||||
|
@ -72,28 +69,32 @@ def makefunc(a):
|
||||||
else:
|
else:
|
||||||
result = ffi.string(result).decode('utf-8')
|
result = ffi.string(result).decode('utf-8')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def makeStructHelper(struct):
|
def makeStructHelper(struct):
|
||||||
def func(*args):
|
def func(*args):
|
||||||
return ffi.new(f"struct {struct} *", args)[0]
|
return ffi.new(f"struct {struct} *", args)[0]
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
for name, attr in getmembers(rl):
|
for name, attr in getmembers(rl):
|
||||||
#print(name, attr)
|
# print(name, attr)
|
||||||
uname = inflection.underscore(name).replace('3_d','_3d').replace('2_d','_2d')
|
uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
|
||||||
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
|
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(
|
||||||
#print(attr.__call__)
|
type(attr)) == "<class '_cffi_backend._CDataBase'>":
|
||||||
#print(attr.__doc__)
|
# print(attr.__call__)
|
||||||
#print(attr.__text_signature__)
|
# print(attr.__doc__)
|
||||||
#print(dir(attr))
|
# print(attr.__text_signature__)
|
||||||
#print(dir(attr.__repr__))
|
# print(dir(attr))
|
||||||
|
# print(dir(attr.__repr__))
|
||||||
f = makefunc(attr)
|
f = makefunc(attr)
|
||||||
setattr(current_module, uname, f)
|
setattr(current_module, uname, f)
|
||||||
#def wrap(*args):
|
# def wrap(*args):
|
||||||
# print("call to ",attr)
|
# print("call to ",attr)
|
||||||
#setattr(PyRay, uname, lambda *args: print("call to ",attr))
|
# setattr(PyRay, uname, lambda *args: print("call to ",attr))
|
||||||
else:
|
else:
|
||||||
setattr(current_module, name, attr)
|
setattr(current_module, name, attr)
|
||||||
|
|
||||||
|
|
Reference in a new issue