[MacRuby-devel] Using AXObserverCreate with macruby

Laurent Sansonetti lsansonetti at apple.com
Sun May 24 10:21:17 PDT 2009


Hi Benjamin,

On May 24, 2009, at 10:05 AM, Benjamin Mollenhauer wrote:

> Hello,
>
> how can I use a ruby function as an parameter to AXObserverCreate?
>> extern AXError AXObserverCreate ( pid_t application,  
>> AXObserverCallback callback, AXObserverRef *outObserver);
>
> It requires an AXObserverCallback, defined as
>> typedef void ( *AXObserverCallback)(
>>    AXObserverRef observer,
>>    AXUIElementRef element,
>>    CFStringRef notification,
>>    void *refcon);
>
> http://developer.apple.com/documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement%5Fh/CompositePage.html#/ 
> /apple%5Fref/c/tdef/AXObserverCallback
>
> I wrote a Obj.-C class (http://pastie.org/488213)  to to access  
> those functions, but how could I use ruby code as a callback?

C function pointers are (as of trunk) not supported yet. But they will  
be supported in 0.5 in the same way RubyCocoa does (accepting Proc  
objects). In the meantime it's surely safer to use an intermediate  
Objective-C class.

HTH,
Laurent


More information about the MacRuby-devel mailing list