1
1
from raylib .static import rl , ffi
2
2
3
- from inspect import ismethod ,getmembers ,isbuiltin
4
- import inflection
5
-
3
+ from inspect import ismethod , getmembers , isbuiltin
4
+ import inflection , sys
6
5
7
6
print ("""from typing import Any
8
7
@@ -23,36 +22,61 @@ def ctype_to_python_type(t):
23
22
return "float"
24
23
elif "char *" in t :
25
24
return "str"
25
+ elif "char" in t :
26
+ return "str" # not sure about this one
26
27
elif "*" in t :
27
28
return "Any"
28
29
elif t .startswith ("struct" ):
29
- return "Any" # This should be CData but cant get PyCharm to understand that - it just shows up as None
30
+ return t . replace ( "struct " , "" )
30
31
elif t .startswith ("unsigned" ):
31
- return t .replace ("unsigned " ,"" )
32
+ return t .replace ("unsigned " , "" )
32
33
else :
33
34
return t
34
35
36
+
35
37
for name , attr in getmembers (rl ):
36
38
uname = inflection .underscore (name ).replace ('3_d' , '_3d' ).replace ('2_d' , '_2d' )
37
39
if isbuiltin (attr ) or str (type (attr )) == "<class '_cffi_backend.__FFIFunctionWrapper'>" :
38
40
39
-
40
41
sig = ""
41
42
for i , arg in enumerate (ffi .typeof (attr ).args ):
42
- param_name = arg .cname .replace ("struct" ,"" ).replace ("char *" ,"str" ).replace ("*" ,"_pointer" ).replace (" " ,"" )
43
+ param_name = arg .cname .replace ("struct" , "" ).replace ("char *" , "str" ).replace ("*" ,
44
+ "_pointer" ).replace (
45
+ " " , "" )
43
46
param_type = ctype_to_python_type (arg .cname )
44
47
sig += f", { param_name } _{ i } : { param_type } "
45
48
46
-
47
49
return_type = ffi .typeof (attr ).result .cname
48
50
51
+ print (
52
+ f' def { uname } (self{ sig } ) -> { ctype_to_python_type (return_type )} :\n """{ attr .__doc__ } """\n ...' )
53
+
54
+ elif str (type (attr )) == "<class '_cffi_backend._CDataBase'>" :
55
+ return_type = ffi .typeof (attr ).result .cname
56
+ print (
57
+ f' def { uname } (self, *args) -> { ctype_to_python_type (return_type )} :\n """VARARG FUNCTION - MAY NOT BE SUPPORTED BY CFFI"""\n ...' )
58
+ else :
59
+ #print("*****", str(type(attr)))
60
+ print (f" { name } : { str (type (attr ))[8 :- 2 ]} " ) # this isolates the type
49
61
50
- print (f" def { uname } (self{ sig } ) -> { ctype_to_python_type (return_type )} : ..." )
62
+ for struct in ffi .list_types ()[0 ]:
63
+ print ("processing" , struct , file = sys .stderr )
64
+ if ffi .typeof (struct ).kind == "struct" :
65
+ if ffi .typeof (struct ).fields is None :
66
+ print ("weird empty struct, skipping" , file = sys .stderr )
67
+ break
68
+ print (f" class { struct } :" )
69
+ sig = ""
70
+ for arg in ffi .typeof (struct ).fields :
71
+ sig += ", " + arg [0 ]
72
+ print (f" def __init__(self{ sig } ):" )
51
73
74
+ for arg in ffi .typeof (struct ).fields :
75
+ print (f" self.{ arg [0 ]} ={ arg [0 ]} " )
52
76
77
+ elif ffi .typeof (struct ).kind == "enum" :
78
+ print (f" { struct } : int" )
53
79
else :
54
- print (f" { name } : { str ( type ( attr ))[ 8 : - 2 ] } " ) # this isolates the type
80
+ print ("ERROR UNKNOWN TYPE" , ffi . typeof ( struct ), file = sys . stderr )
55
81
56
82
57
- for struct in ffi .list_types ()[0 ]:
58
- print (f" { struct } : Any" ) # This should be CData but cant get PyCharm to understand that - it just shows up as None
0 commit comments