Show HN: Autowrap C functions at runtime for the Python/C API
github.com
github.com
def py_do_something(float a, float b):
return c_do_something(a,b)
while, during the Pyx -> .c compilation step, taking care of all the C API plumbing (refcounting, initializing a module structure, type checking etc.)A clear example of why this is useful is shown in the demo about overwriting __getattr__ etc. A static tool will just generate N number of getters and setters.
Pyrex/Cython are both pretty cool. I developed this for helping me with embedding python on an existing C codebase. Something those two things can't do. Similarly ctypes is great for doing it the other way around but doesn't work well for embedding and also doesn't do the automatic conversion so well.
I (of course) had to start reading the code to figure out what was going on, and saw that what looks like a function call is in fact a macro. That explains the "how" but (again, for me) it really doesn't come close to making it feel natural.
C code should look like C code, and you can't write a function that takes a bare "int" as an argument.
See va_args for an example of naked types being passed in the standard library. Really it is not much different from the fact you have to pass a format string to printf.