update docstrings using raylib_api.json

This commit is contained in:
richard 2021-09-23 09:44:08 +01:00
parent a98e0bef65
commit 9a3ffb525e
18 changed files with 15591 additions and 8105 deletions

View file

@ -15,15 +15,10 @@
from raylib.static import rl, ffi from raylib.static import rl, ffi
from inspect import ismethod, getmembers, isbuiltin from inspect import ismethod, getmembers, isbuiltin
import inflection, sys import inflection, sys, json
print("""from typing import Any
class PyRay:
def pointer(self, struct):
return ffi.addressof(struct)
""")
f = open("raylib_api.json", "r")
js = json.load(f)
def ctype_to_python_type(t): def ctype_to_python_type(t):
if t == '_Bool': if t == '_Bool':
@ -47,23 +42,44 @@ def ctype_to_python_type(t):
else: else:
return t return t
print("""from typing import Any
class PyRay:
def pointer(self, struct):
return ffi.addressof(struct)
""")
for name, attr in getmembers(rl): for name, attr in getmembers(rl):
uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d') uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>": if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>":
json_array = [x for x in js['functions'] if x['name'] == name]
json_object = {}
if len(json_array) > 0:
json_object = json_array[0]
sig = "" sig = ""
for i, arg in enumerate(ffi.typeof(attr).args): for i, arg in enumerate(ffi.typeof(attr).args):
param_name = arg.cname.replace("struct", "").replace("char *", "str").replace("*", param_name = arg.cname.replace("struct", "").replace("char *", "str").replace("*",
"_pointer").replace( "_pointer").replace(
" ", "") " ", "")+"_"+str(i)
if 'params' in json_object:
p = json_object['params']
param_name = list(p)[i]
param_type = ctype_to_python_type(arg.cname) param_type = ctype_to_python_type(arg.cname)
sig += f", {param_name}_{i}: {param_type}" sig += f", {param_name}: {param_type}"
return_type = ffi.typeof(attr).result.cname return_type = ffi.typeof(attr).result.cname
description = attr.__doc__
if 'description' in json_object:
description = json_object['description']
print( print(
f' def {uname}(self{sig}) -> {ctype_to_python_type(return_type)}:\n """{attr.__doc__}"""\n ...') f' def {uname}(self{sig}) -> {ctype_to_python_type(return_type)}:\n """{description}"""\n ...')
elif str(type(attr)) == "<class '_cffi_backend._CDataBase'>": elif str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
return_type = ffi.typeof(attr).result.cname return_type = ffi.typeof(attr).result.cname
@ -75,11 +91,16 @@ for name, attr in getmembers(rl):
for struct in ffi.list_types()[0]: for struct in ffi.list_types()[0]:
print("processing", struct, file=sys.stderr) print("processing", struct, file=sys.stderr)
# json_array = [x for x in js['structs'] if x['name'] == name]
# json_object = {}
# if len(json_array) > 0:
# json_object = json_array[0]
if ffi.typeof(struct).kind == "struct": if ffi.typeof(struct).kind == "struct":
if ffi.typeof(struct).fields is None: if ffi.typeof(struct).fields is None:
print("weird empty struct, skipping", file=sys.stderr) print("weird empty struct, skipping", file=sys.stderr)
break break
print(f" class {struct}:") print(f" class {struct}:")
print(f' """ comment """')
sig = "" sig = ""
for arg in ffi.typeof(struct).fields: for arg in ffi.typeof(struct).fields:
sig += ", " + arg[0] sig += ", " + arg[0]

View file

@ -15,13 +15,12 @@
from raylib.static import rl, ffi from raylib.static import rl, ffi
from inspect import ismethod, getmembers, isbuiltin from inspect import ismethod, getmembers, isbuiltin
import inflection, sys import inflection, sys, json
print("""from typing import Any f = open("raylib_api.json", "r")
js = json.load(f)
class struct: ...
""")
def ctype_to_python_type(t): def ctype_to_python_type(t):
@ -47,22 +46,38 @@ def ctype_to_python_type(t):
return t return t
print("""from typing import Any
class struct: ...
""")
for name, attr in getmembers(rl): for name, attr in getmembers(rl):
uname = name uname = name
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>": if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>":
json_array = [x for x in js['functions'] if x['name'] == name]
json_object = {}
if len(json_array) > 0:
json_object = json_array[0]
sig = "" sig = ""
for i, arg in enumerate(ffi.typeof(attr).args): for i, arg in enumerate(ffi.typeof(attr).args):
param_name = arg.cname.replace("struct", "").replace("char *", "str").replace("*", param_name = arg.cname.replace("struct", "").replace("char *", "str").replace("*",
"_pointer").replace( "_pointer").replace(
" ", "") " ", "")+"_"+str(i)
if 'params' in json_object:
p = json_object['params']
param_name = list(p)[i]
param_type = ctype_to_python_type(arg.cname) param_type = ctype_to_python_type(arg.cname)
sig += f"{param_name}_{i}: {param_type}," sig += f"{param_name}: {param_type},"
return_type = ffi.typeof(attr).result.cname return_type = ffi.typeof(attr).result.cname
description = attr.__doc__
if 'description' in json_object:
description = json_object['description']
print( print(
f'def {uname}({sig}) -> {ctype_to_python_type(return_type)}:\n """{attr.__doc__}"""\n ...') f'def {uname}({sig}) -> {ctype_to_python_type(return_type)}:\n """{description}"""\n ...')
elif str(type(attr)) == "<class '_cffi_backend._CDataBase'>": elif str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
return_type = ffi.typeof(attr).result.cname return_type = ffi.typeof(attr).result.cname

View file

@ -38,7 +38,7 @@ However, here is a list of available functions:
Functions API reference Functions API reference
----------------------- -----------------------
.. automodule:: raylib.static.rl .. autoapimodule:: raylib.static
:members: :members:
:undoc-members: :undoc-members:

View file

@ -38,7 +38,7 @@ However, here is a list of available functions:
Functions API reference Functions API reference
----------------------- -----------------------
.. automodule:: raylib.static.rl .. autoapimodule:: raylib.static
:members: :members:
:undoc-members: :undoc-members:

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -103,7 +103,7 @@
<tr class="cg-1"> <tr class="cg-1">
<td></td> <td></td>
<td>&#160;&#160;&#160; <td>&#160;&#160;&#160;
<a href="raylib.html#module-raylib.static.rl"><code class="xref">raylib.static.rl</code></a></td><td> <a href="raylib.html#module-raylib.static"><code class="xref">raylib.static</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
</table> </table>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

6668
raylib_api.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@ pyray = PyRay()
pyray.init_window(800, 450, "Raylib texture test") pyray.init_window(800, 450, "Raylib texture test")
pyray.set_target_fps(60) pyray.set_target_fps(60)
camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
image = pyray.load_image("examples/models/resources/heightmap.png") image = pyray.load_image("examples/models/resources/heightmap.png")
texture = pyray.load_texture_from_image(image) texture = pyray.load_texture_from_image(image)