update docstrings using raylib_api.json
This commit is contained in:
parent
a98e0bef65
commit
9a3ffb525e
18 changed files with 15591 additions and 8105 deletions
|
@ -15,15 +15,10 @@
|
|||
from raylib.static import rl, ffi
|
||||
|
||||
from inspect import ismethod, getmembers, isbuiltin
|
||||
import inflection, sys
|
||||
|
||||
print("""from typing import Any
|
||||
|
||||
class PyRay:
|
||||
def pointer(self, struct):
|
||||
return ffi.addressof(struct)
|
||||
""")
|
||||
import inflection, sys, json
|
||||
|
||||
f = open("raylib_api.json", "r")
|
||||
js = json.load(f)
|
||||
|
||||
def ctype_to_python_type(t):
|
||||
if t == '_Bool':
|
||||
|
@ -47,23 +42,44 @@ def ctype_to_python_type(t):
|
|||
else:
|
||||
return t
|
||||
|
||||
print("""from typing import Any
|
||||
|
||||
class PyRay:
|
||||
def pointer(self, struct):
|
||||
return ffi.addressof(struct)
|
||||
""")
|
||||
|
||||
|
||||
|
||||
|
||||
for name, attr in getmembers(rl):
|
||||
uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
|
||||
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 = ""
|
||||
for i, arg in enumerate(ffi.typeof(attr).args):
|
||||
param_name = arg.cname.replace("struct", "").replace("char *", "str").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)
|
||||
sig += f", {param_name}_{i}: {param_type}"
|
||||
sig += f", {param_name}: {param_type}"
|
||||
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
|
||||
description = attr.__doc__
|
||||
|
||||
if 'description' in json_object:
|
||||
description = json_object['description']
|
||||
|
||||
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'>":
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
|
@ -75,11 +91,16 @@ for name, attr in getmembers(rl):
|
|||
|
||||
for struct in ffi.list_types()[0]:
|
||||
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).fields is None:
|
||||
print("weird empty struct, skipping", file=sys.stderr)
|
||||
break
|
||||
print(f" class {struct}:")
|
||||
print(f' """ comment """')
|
||||
sig = ""
|
||||
for arg in ffi.typeof(struct).fields:
|
||||
sig += ", " + arg[0]
|
||||
|
|
|
@ -15,13 +15,12 @@
|
|||
from raylib.static import rl, ffi
|
||||
|
||||
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):
|
||||
|
@ -47,22 +46,38 @@ def ctype_to_python_type(t):
|
|||
return t
|
||||
|
||||
|
||||
print("""from typing import Any
|
||||
|
||||
class struct: ...
|
||||
|
||||
""")
|
||||
|
||||
for name, attr in getmembers(rl):
|
||||
uname = name
|
||||
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 = ""
|
||||
for i, arg in enumerate(ffi.typeof(attr).args):
|
||||
param_name = arg.cname.replace("struct", "").replace("char *", "str").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)
|
||||
sig += f"{param_name}_{i}: {param_type},"
|
||||
sig += f"{param_name}: {param_type},"
|
||||
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
description = attr.__doc__
|
||||
|
||||
if 'description' in json_object:
|
||||
description = json_object['description']
|
||||
|
||||
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'>":
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -38,7 +38,7 @@ However, here is a list of available functions:
|
|||
Functions API reference
|
||||
-----------------------
|
||||
|
||||
.. automodule:: raylib.static.rl
|
||||
.. autoapimodule:: raylib.static
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ However, here is a list of available functions:
|
|||
Functions API reference
|
||||
-----------------------
|
||||
|
||||
.. automodule:: raylib.static.rl
|
||||
.. autoapimodule:: raylib.static
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
|
2967
docs/genindex.html
2967
docs/genindex.html
File diff suppressed because it is too large
Load diff
BIN
docs/objects.inv
BIN
docs/objects.inv
Binary file not shown.
|
@ -103,7 +103,7 @@
|
|||
<tr class="cg-1">
|
||||
<td></td>
|
||||
<td>   
|
||||
<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>
|
||||
</table>
|
||||
|
||||
|
|
2231
docs/pyray.html
2231
docs/pyray.html
File diff suppressed because it is too large
Load diff
6257
docs/raylib.html
6257
docs/raylib.html
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
2762
raylib/pyray.pyi
2762
raylib/pyray.pyi
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
6668
raylib_api.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,7 @@ pyray = PyRay()
|
|||
pyray.init_window(800, 450, "Raylib texture test")
|
||||
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)
|
||||
image = pyray.load_image("examples/models/resources/heightmap.png")
|
||||
texture = pyray.load_texture_from_image(image)
|
||||
|
|
Reference in a new issue