After a grueling Saturday coding session, I have finally placed the last
puzzle piece for wrapping the DarwiinRemote WiiRemote.framework.
You can see the resulting code at
http://enja.org/enjapen
(check out WiiMote.py for the informal_protocol)
I want to mention that I think this fix should be documented, as I could
find NO example anywhere in the docs or on any blog on the internet. The
main hang up was wrapping an interface method for the WiiRemoteDelegate:
> - (void) rawIRData: (IRData[4]) irData;
>
Where the IRData is a struct defined as:
typedef struct {
> int x, y, s;
> } IRData;
>
with IRData defined in python like:
IRData = objc.createStructType("IRData", "iii", ["x", "y", "s"])
So our python function needs to accept an array of 4 IRData structs.
The signature for this needs to be:
v@:n^[4{IRData=iii}]
>
Which we define in the informal_protocol (or with python 2.4/2.5 using
@objc.selector(...) )
The problem is, nowhere is it documented that "n^" is necessary. I figured
it out by dumb luck and a slightly intuitive (but probably wrong) feeling
about arrays being pointers in C (true in objective-c?)
This page gave me good info:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_13_section_9.html
but little did I know what a "method encoding" was. I guess "n" means this
object is given as input.
I'm only guessing, but if I were trying to wrap a function that returned an
array (which you can't do, just like C, I guess you would get a pointer?)
you would have to use "o^"?
I know part of this is my fault for being new to Objective-C and having a
shallow understanding of C, but I'm not the only one who could have been
served by one example of wrapping a function that has a complex data type. I
hope this helps others who might have wrestled with this!
I want to extend a BIG thanks to the pyobjc team for letting me stay in
python paradise when making apps on the mac :)
--
Ian Johnson
Ignorance is Piss.
|