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]
|
||||
|
|
Reference in a new issue