Hi Dave, Sorry for the late reply.
I'm afraid it's not currently possible to pass a string as an API that accepts a 'void *' (which seems to be your case). If you file a ticket on the tracker we can address this problem. Your Pointer.new call may not raise a runtime exception but I suspect it's not going to behave correctly later. I'm not familiar with the API you are using but it seems very uncommon to pass constants as context arguments to alter behaviors. Maybe there is another way to do what you want? Laurent On May 17, 2010, at 2:25 AM, Dave Baldwin wrote: > Digging a bit more I think a solution to my own questions is: > > On 13 May 2010, at 14:33, Dave Baldwin wrote: > >> I am trying to translate code that looks like this: >> >> static NSString *SKTWindowControllerCanvasSizeObservationContext = >> @"com.apple.SKTWindowController.canvasSize"; >> >> and later >> >> [[self document] addObserver:self forKeyPath:SKTDocumentCanvasSizeKey >> options:NSKeyValueObservingOptionNew >> context:SKTWindowControllerCanvasSizeObservationContext]; >> >> to Ruby: >> >> SKTWindowControllerCanvasSizeObservationContext = >> "com.apple.SKTWindowController.canvasSize" > > SKTWindowControllerCanvasSizeObservationContext = Pointer.new(:char) > > as all we are after is a unique value. I still don't understand why the > original version wasn't acceptable as the documentation says the context > argument can be a C pointer or an object reference. Anyhow, this has got me > past this point but I have still to prove the final result when it is used by > the observer. > >> document.addObserver(self, forKeyPath: SKTDocumentCanvasSizeKey, >> options: >> NSKeyValueObservingOptionNew, >> >> context:SKTWindowControllerCanvasSizeObservationContext) >> >> but when it runs I get this error: >> >> expected instance of Pointer, got >> `"com.apple.SKTWindowController.canvasSize"' (String) (TypeError) >> >> How do I get the a pointer to the context string? All the examples I have >> found for the Pointer class seem to expect an objective C routing to fill it >> in. >> >> Thanks, >> >> Dave. >> >> > > Dave. > > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel