|
1 | | -import sys, os, ctypes |
| 1 | +import sys, os, ctypes, _ctypes |
2 | 2 |
|
3 | 3 | if "PYSDL3_DISABLE_DOCS" not in os.environ: |
4 | 4 | os.environ["PYSDL3_DISABLE_DOCS"] = "0" |
@@ -30,20 +30,29 @@ def SDL_FUNC(name, retType, *args): |
30 | 30 | with open(__docs_file__, "w") as file: |
31 | 31 | result = "from .SDL import *\n\n" |
32 | 32 | result += "from .__init__ import ctypes, dll\n\n" |
| 33 | + definitions, types = "", set() |
33 | 34 |
|
34 | 35 | for index, name in enumerate(functions.keys()): |
35 | 36 | retType, args = functions[name].restype, functions[name].argtypes |
36 | | - getType = lambda i: "None" if i is None else ("ctypes." if "SDL_" not in i.__name__ else "") \ |
37 | | - + i.__name__.replace("CFunctionType", "_CFuncPtr").replace("LP_", "") |
38 | 37 |
|
39 | | - result += f"def {name}({", ".join([f"_{index}: {getType(i)}" for index, i in enumerate(args)])}) -> {getType(retType)}:\n" |
40 | | - result += f" \"\"\"This function is auto-generated.\"\"\"\n" |
41 | | - result += f" return dll.{name}({", ".join([f"_{index}" for index, i in enumerate(args)])})" |
| 38 | + def getName(i): |
| 39 | + if i is None: return "None" |
| 40 | + name = i.__name__.replace("CFunctionType", "_CFuncPtr") |
| 41 | + if "SDL_" in name or "LP_" in name: types.add(name); return name |
| 42 | + else: return f"ctypes.{name}" |
| 43 | + |
| 44 | + definitions += f"def {name}({", ".join([f"_{index}: {getName(i)}" for index, i in enumerate(args)])}) -> {getName(retType)}:\n" |
| 45 | + definitions += f" \"\"\"This function is auto-generated.\"\"\"\n" |
| 46 | + definitions += f" return dll.{name}({", ".join([f"_{index}" for index, i in enumerate(args)])})" |
42 | 47 |
|
43 | 48 | if index != len(functions.keys()) - 1: |
44 | | - result += "\n\n" |
45 | | - |
46 | | - file.write(result) |
| 49 | + definitions += "\n\n" |
| 50 | + |
| 51 | + for i in types: |
| 52 | + result += f"class {i}(ctypes._Pointer):\n" |
| 53 | + result += " \"\"\"This class is auto-generated.\"\"\"\n\n" |
| 54 | + |
| 55 | + file.write(result + definitions) |
47 | 56 |
|
48 | 57 | from .__docs__ import * |
49 | 58 |
|
|
0 commit comments