Auto-generating ctypes wrappers (Overriding the auto-generation for fun and profit...)
Last update on .
The default ctypes auto-generated wrappers are really quite expensive, so I wanted to rework them. Luckily the entire function-generating operation is a single overridable method. The methods now look like this:
Comments are closed.
Pingbacks are closed.
Thomas Heller on 05/13/2005 8:47 a.m. #
The generated code looks nicer with decorator syntax<br />
@cdecl(None, 'libGL', [GLclampf, GLclampf, GLclampf, GLclampf])<br />
def glBlendColor(red, green, blue, alpha):<br />
# /usr/include/GL/gl.h 1652<br />
return glBlendColor._api_(red, green, blue, alpha)<br />
but that wasn't your point.<br />
The reason I did it in that way is that a Python function is generated, which could also be changed manually.<br />
I did not find a way to reliably detect an empty function body, in that case I would have commented out the<br />
<pre> return glBlendColor._api_(red, green, blue, alpha)</pre> line. Wouldn't also this function behave correctly in pydoc?<br />
Please note that I would prefer to discuss all this on the ctypes-users list instead of blog comments, but I'm sure you will post your findings there...<br />
Mike Fletcher on 05/13/2005 9:15 a.m. #
Can't really use the decorators if we want to support Python 2.2. I'm intending to post to ctypes-users when I've actually figured out what works, rather than just tossing in random "I'm trying this now" posts... maybe I should; a little randomness never hurt anyone.
Thomas Heller on 05/13/2005 1:15 p.m. #
I hope you mean Python 2.3, not 2.2? ctypes does require the former.
Mike Fletcher on 05/13/2005 1:53 p.m. #
Hmm, had meant 2.2. Didn't realise ctypes was 2.3+. I suppose we can ditch 2.2 compatability... the old versions will still be around for the 2.2 users.