Hi Paul, On May 6, 2010, at 7:59 PM, Paul Howson wrote:
> I need some help with this example which arises at the boundary between > MacRuby and the C Core Text framework. > > Consider the following Core Text function definition: > > void CTFrameGetLineOrigins( CTFrameRef frame, CFRange range, CGPoint > origins[] ) > > The third argument is defined as: > > "origins > The buffer to which the origins are copied. The buffer must have at least as > many elements as specified by range's length." > > Clearly origins is a buffer and a series of CGPoint structures are copied > into it. > > How can this be handled in MacRuby? Specifically: > > 1. What kind of argument should be passed? Presumably something constructed > using the Pointer.new_with_type() function? Documentation on this function is > very hard to find. You're right, the Pointer class must be used. Sorry about the lack of documentation. Here is a snippet that might work: # n must be defined origins = Pointer.new(CGPoint.type, n) # this builds a pointer to n times CGPoint CTFrameGetLineOrigins(frame, CFRange.new(0, n), origins) > 2. How to access the individual CGPoints in the returned buffer? This is not > an Objective-C / MacRuby array object. It is just an address to a buffer. > Easy to do in C, but how to do in MacRuby? Using Pointer#[] you can simply dereference a given slot in the pointer, as in C. n.times { |i| p origins[i] } # should print nth points Let me know if this works or not for you. Laurent _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel