-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcreate_define_consts.py
105 lines (98 loc) · 4.4 KB
/
create_define_consts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) 2021 Richard Smith and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# licenses when the conditions for such availability set forth in the Eclipse
# Public License, v. 2.0 are satisfied: GNU General Public License, version 2
# with the GNU Classpath Exception which is
# available at https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
from raylib import rl, ffi
from inspect import ismethod, getmembers, isbuiltin
import inflection, sys, json, re
two_or = re.compile(r'''\(\s*([^\s]*)\s*\|\s*([^\s]*)\s*\)''')
three_or = re.compile(r'''\(\s*([^\s]*)\s*\|\s*([^\s]*)\s*\|\s*(^\s*)\s*\)''')
two_mult = re.compile(r'''\(\s*([^\s]*)\s*\*\s*([^\s]*)\s*\)''')
two_div = re.compile(r'''\(\s*([^\s]*)\s*/\s*([^\s]*)\s*\)''')
def process(filename):
f = open(filename, "r")
js = json.load(f)
known_define = []
known_enum = []
for e in js['enums']:
if e['name'] and e['values']:
for v in e['values']:
if v['name']:
known_enum.append(str(v['name']).strip())
for e in js['defines']:
if e['type'] in ('INT', 'FLOAT', 'STRING'):
if e['type'] == 'INT':
print(e['name'] + ": int = " + str(e['value']).strip())
elif e['type'] == 'FLOAT':
print(e['name'] + ": float = " + str(e['value']).strip())
else:
print(e['name'] + ": str = \"" + str(e['value']).strip() + '"')
known_define.append(str(e['name']).strip())
elif e['type'] == "UNKNOWN":
strval = str(e['value']).strip()
if strval.startswith("__"):
continue
if strval in known_enum:
print(e['name'] + " = raylib." + strval)
elif strval in known_define:
print(e['name'] + " = " + strval)
else:
matches = two_or.match(strval)
if not matches:
matches = three_or.match(strval)
if matches:
match_defs = [str(m).strip() for m in matches.groups()]
if all(d in known_enum for d in match_defs):
print(e['name'] + " = " + " | ".join(("raylib."+m) for m in match_defs))
elif all(d in known_define for d in match_defs):
print(e['name'] + " = " + " | ".join(match_defs))
else:
continue
known_define.append(str(e['name']).strip())
elif e['type'] == "FLOAT_MATH":
strval = str(e['value']).strip()
matches = two_mult.match(strval)
if matches:
match_defs = [str(m).strip() for m in matches.groups()]
match_parts = []
for m in match_defs:
if "." in m:
match_parts.append(m.rstrip("f"))
else:
match_parts.append(m)
if all(d in known_enum for d in match_parts):
print(e['name'] + " = " + " * ".join(("raylib." + m) for m in match_parts))
elif all(d in known_define for d in match_parts):
print(e['name'] + " = " + " * ".join(match_parts))
else:
matches = two_div.match(strval)
if matches:
match_defs = [str(m).strip() for m in matches.groups()]
match_parts = []
for m in match_defs:
if "." in m:
match_parts.append(m.rstrip("f"))
else:
match_parts.append(m)
if any(d in known_enum for d in match_parts):
print(e['name'] + " = " + " / ".join(("raylib." + m) for m in match_parts))
elif any(d in known_define for d in match_parts):
print(e['name'] + " = " + " / ".join(match_parts))
else:
continue
print("import raylib\n")
process("raylib.json")
process("raymath.json")
process("rlgl.json")
process("raygui.json")
process("physac.json")
process("glfw3.json")