From ed018b2b7771d0fc27bce0cb2b701d8bada57e7b Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 2 Feb 2022 20:32:12 +0000 Subject: [PATCH] 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 --- pyray/__init__.py | 21 +++++++++++++-------- version.py | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pyray/__init__.py b/pyray/__init__.py index a050c26..e8d7f74 100644 --- a/pyray/__init__.py +++ b/pyray/__init__.py @@ -65,14 +65,19 @@ def makefunc(a): def func(*args): modified_args = [] for (c_arg, arg) in zip(ffi.typeof(a).args, args): - #print(arg, c_arg.kind) - if type(arg) == str: - encoded = arg.encode('utf-8') - modified_args.append(encoded) - elif c_arg.kind == 'pointer' and str(type(arg)) == "": - modified_args.append(ffi.addressof(arg)) - else: - modified_args.append(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 type(arg) == str: + arg = arg.encode('utf-8') + elif type(arg) is bool: + arg = ffi.new("bool *", arg) + elif type(arg) is int: + arg = ffi.new("int *", arg) + elif type(arg) is float: + arg = ffi.new("float *", arg) + elif str(type(arg)) == "" and "*" not in str(arg): + arg = ffi.addressof(arg) + modified_args.append(arg) result = a(*modified_args) if result is None: return diff --git a/version.py b/version.py index f23b4f9..48a6af4 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "4.0.0.3" \ No newline at end of file +__version__ = "4.0.0.4" \ No newline at end of file