Fujimoto Hisa
hisa****@fobj*****
Wed Mar 14 14:57:52 JST 2007
Hi Laurent On 2007/03/14, at 9:23, Laurent Sansonetti wrote: > Hi guys, > > I recently committed support for function-pointers arguments and > return value of functions and methods. It means that you can now use > them from RubyCocoa. > > How does it work? gen_bridge_metadata.rb has been modified to detect > them and provide some additional XML markup. RubyCocoa at runtime > detects the markup and will convert Ruby Proc objects into function- > pointers, by creating an intermediate Libffi closure. excellent!! > Practically: > > $ irb -r osx/foundation >>> include OSX > => Object >>> ary = NSMutableArray.alloc.init > => #<OSX::NSCFArray:0x83d768 class='NSCFArray' id=0x125fd20> >>> [5,3,2,4,1].each { |i| ary.addObject(i) } > => [5, 3, 2, 4, 1] >>> ary.sortUsingFunction_context(proc { |x, y, ctx| x.intValue <=> > y.intValue }, nil) > => nil >>> ary.to_a.map { |x| x.to_i } > => [1, 2, 3, 4, 5] > > Notes: > - for functions/methods accepting only one function-pointer argument, > we might want to accept a block directly (so, > ``ary.sortUsingFunction_context(nil) { |x, y, ctx| ... }''). It's absolutely necessary. I can't think higher-order procedure *without block* for ruby programming ;) -- hisa