raylib 5.0.0.2__cp39-cp39-manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of raylib might be problematic. Click here for more details.
- pyray/__init__.py +143 -0
- pyray/__init__.pyi +4154 -0
- raylib/__init__.py +24 -0
- raylib/__init__.pyi +3929 -0
- raylib/_raylib_cffi.abi3.so +0 -0
- raylib/build.py +219 -0
- raylib/colors.py +41 -0
- raylib/defines.py +494 -0
- raylib/enums.py +714 -0
- raylib/version.py +1 -0
- raylib-5.0.0.2.dist-info/LICENSE +277 -0
- raylib-5.0.0.2.dist-info/METADATA +216 -0
- raylib-5.0.0.2.dist-info/RECORD +15 -0
- raylib-5.0.0.2.dist-info/WHEEL +5 -0
- raylib-5.0.0.2.dist-info/top_level.txt +2 -0
pyray/__init__.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Copyright (c) 2021 Richard Smith and others
|
|
2
|
+
#
|
|
3
|
+
# This program and the accompanying materials are made available under the
|
|
4
|
+
# terms of the Eclipse Public License 2.0 which is available at
|
|
5
|
+
# http://www.eclipse.org/legal/epl-2.0.
|
|
6
|
+
#
|
|
7
|
+
# This Source Code may also be made available under the following Secondary
|
|
8
|
+
# licenses when the conditions for such availability set forth in the Eclipse
|
|
9
|
+
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
|
|
10
|
+
# with the GNU Classpath Exception which is
|
|
11
|
+
# available at https://www.gnu.org/software/classpath/license.html.
|
|
12
|
+
#
|
|
13
|
+
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
14
|
+
import re
|
|
15
|
+
import weakref
|
|
16
|
+
from array import array
|
|
17
|
+
|
|
18
|
+
from raylib import rl, ffi
|
|
19
|
+
from raylib.colors import *
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from raylib.defines import *
|
|
23
|
+
except AttributeError:
|
|
24
|
+
print("sorry deprecated enums dont work on dynamic version")
|
|
25
|
+
|
|
26
|
+
from inspect import getmembers, isbuiltin
|
|
27
|
+
|
|
28
|
+
current_module = __import__(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _underscore(word: str) -> str:
|
|
32
|
+
"""
|
|
33
|
+
from inflection
|
|
34
|
+
"""
|
|
35
|
+
word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
|
|
36
|
+
word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
|
|
37
|
+
word = word.replace("-", "_")
|
|
38
|
+
return word.lower()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def pointer(struct):
|
|
42
|
+
return ffi.addressof(struct)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# I'm concerned that we are doing a lot of string comparisons on every function call to detect types.
|
|
46
|
+
# Quickest way would probably be isinstance(result, ffi._backend._CDataBase) but that class name varies
|
|
47
|
+
# depending on if binding is static/dynamic
|
|
48
|
+
# (and possibly also different on pypy implementations?).
|
|
49
|
+
# which makes me reluctant to rely on it.
|
|
50
|
+
# Another possibility is ffi.typeof() but that will throw an exception if you give it a type that isn't a ctype
|
|
51
|
+
# Another way to improve performance might be to special-case simple types before doing the string comparisons
|
|
52
|
+
|
|
53
|
+
def _wrap_function(original_func):
|
|
54
|
+
# print("makefunc ",a, ffi.typeof(a).args)
|
|
55
|
+
def wrapped_func(*args):
|
|
56
|
+
modified_args = []
|
|
57
|
+
for (c_arg, arg) in zip(ffi.typeof(original_func).args, args):
|
|
58
|
+
# print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
|
|
59
|
+
if c_arg.kind == 'pointer':
|
|
60
|
+
if type(arg) is str:
|
|
61
|
+
arg = arg.encode('utf-8')
|
|
62
|
+
# if c_arg is a 'char *' not a 'const char *' then we ought to raise here because its an out
|
|
63
|
+
# parameter and user should supply a ctype pointer, but cffi cant detect const
|
|
64
|
+
# so we would have to get the info from raylib.json
|
|
65
|
+
elif type(arg) is list and str(c_arg) == "<ctype 'char * *'>":
|
|
66
|
+
arg = [ffi.new("char[]", x.encode('utf-8')) for x in arg]
|
|
67
|
+
elif is_cdata(arg) and "*" not in str(arg):
|
|
68
|
+
arg = ffi.addressof(arg)
|
|
69
|
+
elif arg is None:
|
|
70
|
+
arg = ffi.NULL
|
|
71
|
+
elif not is_cdata(arg):
|
|
72
|
+
if str(c_arg) == "<ctype '_Bool *'>":
|
|
73
|
+
raise TypeError(
|
|
74
|
+
"Argument must be a ctype bool, please create one with: pyray.ffi.new('bool *', True)")
|
|
75
|
+
elif str(c_arg) == "<ctype 'int *'>":
|
|
76
|
+
raise TypeError(
|
|
77
|
+
"Argument must be a ctype int, please create one with: pyray.ffi.new('int *', 1)")
|
|
78
|
+
elif str(c_arg) == "<ctype 'float *'>":
|
|
79
|
+
raise TypeError(
|
|
80
|
+
"Argument must be a ctype float, please create one with: pyray.ffi.new('float *', 1.0)")
|
|
81
|
+
modified_args.append(arg)
|
|
82
|
+
result = original_func(*modified_args)
|
|
83
|
+
if result is None:
|
|
84
|
+
return
|
|
85
|
+
elif is_cdata(result) and str(result).startswith("<cdata 'char *'"):
|
|
86
|
+
if str(result) == "<cdata 'char *' NULL>":
|
|
87
|
+
return ""
|
|
88
|
+
else:
|
|
89
|
+
return ffi.string(result).decode('utf-8')
|
|
90
|
+
else:
|
|
91
|
+
return result
|
|
92
|
+
|
|
93
|
+
# apparently pypy and cpython produce different types so check for both
|
|
94
|
+
def is_cdata(arg):
|
|
95
|
+
return str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" or str(
|
|
96
|
+
type(arg)) == "<class '_cffi_backend._CDataBase'>"
|
|
97
|
+
|
|
98
|
+
return wrapped_func
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
global_weakkeydict = weakref.WeakKeyDictionary()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _make_struct_constructor_function(struct):
|
|
105
|
+
def func(*args):
|
|
106
|
+
# print(struct, args)
|
|
107
|
+
modified_args = []
|
|
108
|
+
for (field, arg) in zip(ffi.typeof(struct).fields, args):
|
|
109
|
+
# print("arg:", str(arg), "field:", field[1], "field type:", field[1].type, "type(arg):", str(type(arg)))
|
|
110
|
+
if arg is None:
|
|
111
|
+
arg = ffi.NULL
|
|
112
|
+
elif (field[1].type.kind == 'pointer'
|
|
113
|
+
and (str(type(arg)) == "<class 'numpy.ndarray'>"
|
|
114
|
+
or isinstance(arg, (array, bytes, bytearray, memoryview)))):
|
|
115
|
+
arg = ffi.from_buffer(field[1].type, arg)
|
|
116
|
+
modified_args.append(arg)
|
|
117
|
+
s = ffi.new(f"struct {struct} *", modified_args)[0]
|
|
118
|
+
global_weakkeydict[s] = modified_args
|
|
119
|
+
return s
|
|
120
|
+
|
|
121
|
+
return func
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
for name, attr in getmembers(rl):
|
|
125
|
+
# print(name, attr)
|
|
126
|
+
uname = _underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
|
|
127
|
+
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(
|
|
128
|
+
type(attr)) == "<class '_cffi_backend._CDataBase'>":
|
|
129
|
+
# print(attr.__call__)
|
|
130
|
+
# print(attr.__doc__)
|
|
131
|
+
# print(dir(attr))
|
|
132
|
+
# print(dir(attr.__repr__))
|
|
133
|
+
f = _wrap_function(attr)
|
|
134
|
+
setattr(current_module, uname, f)
|
|
135
|
+
else:
|
|
136
|
+
setattr(current_module, name, attr)
|
|
137
|
+
|
|
138
|
+
for struct in ffi.list_types()[0]:
|
|
139
|
+
f = _make_struct_constructor_function(struct)
|
|
140
|
+
setattr(current_module, struct, f)
|
|
141
|
+
|
|
142
|
+
# overwrite ffi enums with our own
|
|
143
|
+
from raylib.enums import *
|