Re: [Pyobjc-dev] conversion of tuples to structs
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-09-12 07:33:28
|
Tobias Sargeant wrote: > Looking at the code in objc_support.m, it's pretty obvious that > structs (and arrays) can currently only be built from tuples. Is > there any reason why anything that acts as a sequence won't do? Not really. In the Carbon(-ish) wrappers that come with MacPython we've usually made sure this is possible. For example the Carbon.CG module accepts any length-6 sequence where it expects an affine transform. Very useful (especially since I have a Transform class that also behaves as a length-6 sequence ;-). The same goes voor points and rects. > I appreciate that the symmetry of the pythonifying/depythonifying is > neat, but it would be extremely useful (for example) to be able to > pass Numeric arrays representing points to objc functions without the > overhead (both in terms of execution speed and in terms of typing) of > converting them to tuples. > > If there's no reason (technical or otherwise) why this shouldn't be > the case, I'm happy to make the change and submit a patch. I've been thinking the same thing every now and then. I don't know how easy it would be to fix. If those structs were unpacked with PyArg_ParseTuple (and I think they aren't), the fix would be easy: just use PyArg_Parse instead and add parenthesis to the format strings, eg. "ff" would have to become "(ff)". But I have no idea where the struct conversions live in the PyObjC code base... Ronald? Just |