Skip to content

Commit 2c752b5

Browse files
remove all the ints from the pyray hints and docs. (leave them in pyray itself for backwards compability) add proper enums to pyray and to pyray hints/docs (generated from raylib.json). TODO: raygui, rlgl, maybe something for the C API. See issue #52
1 parent d058903 commit 2c752b5

File tree

7 files changed

+715
-515
lines changed

7 files changed

+715
-515
lines changed

create_enums.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
15+
from raylib import rl, ffi
16+
17+
from inspect import ismethod, getmembers, isbuiltin
18+
import inflection, sys, json
19+
20+
f = open("raylib.json", "r")
21+
js = json.load(f)
22+
23+
print("""from enum import IntEnum
24+
""")
25+
26+
for e in js['enums']:
27+
print ("class "+e['name']+"("+"IntEnum):")
28+
for value in e['values']:
29+
print(" "+value['name']+" = "+str(value['value']))
30+
print("")
31+

create_stub_pyray.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def pointer(struct):
8989
f'def {uname}(*args) -> {ctype_to_python_type(return_type)}:\n """VARARG FUNCTION - MAY NOT BE SUPPORTED BY CFFI"""\n ...')
9090
else:
9191
#print("*****", str(type(attr)))
92-
print(f"{name}: {str(type(attr))[8:-2]}") # this isolates the type
92+
t = str(type(attr))[8:-2] # this isolates the type
93+
if t != "int":
94+
print(f"{name}: {t}")
9395

9496
for struct in ffi.list_types()[0]:
9597
print("processing", struct, file=sys.stderr)
@@ -111,8 +113,8 @@ def pointer(struct):
111113
for arg in ffi.typeof(struct).fields:
112114
print(f" self.{arg[0]}={arg[0]}")
113115

114-
elif ffi.typeof(struct).kind == "enum":
115-
print(f"{struct}: int")
116+
#elif ffi.typeof(struct).kind == "enum":
117+
# print(f"{struct}: int")
116118
else:
117119
print("ERROR UNKNOWN TYPE", ffi.typeof(struct), file=sys.stderr)
118120

make_docs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ gcc raylib-c/parser/raylib_parser.c
66
./a.out -i raylib-c/src/raylib.h -o raylib.json -f JSON
77

88
python3 raylib/build.py
9+
10+
python3 create_enums.py > raylib/enums.py
11+
12+
913
pip3 install sphinx-autoapi myst_parser sphinx_rtd_theme
1014
python3 create_stub_pyray.py > pyray/__init__.pyi
15+
python3 create_enums.py >> pyray/__init__.pyi
1116
python3 create_stub_static.py >raylib/__init__.pyi
1217
rm -r docs
1318
cd docs-src

pyray/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ def func(*args):
116116
f = makeStructHelper(struct)
117117
setattr(current_module, struct, f)
118118

119+
# overwrite ffi enums with our own
120+
from raylib.enums import *

0 commit comments

Comments
 (0)