pyray: if function arg requires pointer and is given a pointer, don't try to create a pointer. if given a python primitive(float/int/bool), create an FFI float/int/bool and use pointer to it. https://github.com/electronstudio/raylib-python-cffi/issues/57

This commit is contained in:
richard 2022-02-02 20:32:12 +00:00
parent 7b889a2350
commit ed018b2b77
2 changed files with 14 additions and 9 deletions

View file

@ -65,14 +65,19 @@ def makefunc(a):
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, c_arg.kind) #print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
if type(arg) == str: if c_arg.kind == 'pointer':
encoded = arg.encode('utf-8') if type(arg) == str:
modified_args.append(encoded) arg = arg.encode('utf-8')
elif c_arg.kind == 'pointer' and str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>": elif type(arg) is bool:
modified_args.append(ffi.addressof(arg)) arg = ffi.new("bool *", arg)
else: elif type(arg) is int:
modified_args.append(arg) arg = ffi.new("int *", arg)
elif type(arg) is float:
arg = ffi.new("float *", arg)
elif str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" and "*" not in str(arg):
arg = ffi.addressof(arg)
modified_args.append(arg)
result = a(*modified_args) result = a(*modified_args)
if result is None: if result is None:
return return

View file

@ -1 +1 @@
__version__ = "4.0.0.3" __version__ = "4.0.0.4"