The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Function Pointers in RubyCocoa

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Laurent Sansonetti

Posts: 134
Nickname: lrz
Registered: Jun, 2006

Laurent Sansonetti is a software engineer at Apple Computer and a longtime Ruby enthusiast.
Function Pointers in RubyCocoa Posted: Mar 13, 2007 7:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Laurent Sansonetti.
Original Post: Function Pointers in RubyCocoa
Feed Title: lrz's diary
Feed URL: http://www.chopine.be/lrz/diary/xml/rss/feed.xml
Feed Description: lrz's diary
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Laurent Sansonetti
Latest Posts From lrz's diary

Advertisement

Very recently I committed some early support for C function pointers arguments to RubyCocoa.

  $ irb -r osx/foundation
   >> include OSX
  => Object
   >> ary = NSMutableArray.alloc.init
  => #
   >> [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]

How does it work? gen_bridge_metadata.rb has been modified to detect function-pointer arguments and return value in C functions and Objective-C methods, and provide some additional XML markup. RubyCocoa at runtime detects the markup and will convert Ruby Proc objects into function pointers, by creating intermediate Libffi closures.

RubyCocoa is getting very powerful, it looks like a C bridge now :-)

Read: Function Pointers in RubyCocoa

Topic: So. Previous Topic   Next Topic Topic: 100th No Fluff Just Stuff Symposium

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use