[フレーム]
BT

InfoQ Software Architects' Newsletter

A monthly overview of things you need to know as an architect or aspiring architect.

View an example

We protect your privacy.

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Unlock the full InfoQ experience

Unlock the full InfoQ experience by logging in! Stay updated with your favorite authors and topics, engage with content, and download exclusive resources.

Log In
or

Don't have an InfoQ account?

Register
  • Stay updated on topics and peers that matter to youReceive instant alerts on the latest insights and trends.
  • Quickly access free resources for continuous learningMinibooks, videos with transcripts, and training materials.
  • Save articles and read at anytimeBookmark articles to read whenever youre ready.

Topics

Choose your language

InfoQ Homepage News Ruby FFI Brings Native Library Access to JRuby, MRI

Ruby FFI Brings Native Library Access to JRuby, MRI

Leia em PortuguÃas

This item in japanese

Dec 10, 2008 1 min read

Write for InfoQ

Feed your curiosity. Help 550k+ global
senior developers
each month stay ahead.
Get in touch

MRI and Rubinius have had support for Ruby native extensions, which allow native code to interact with Ruby code and the Ruby interpreter or VM. Ruby 1.8.0 introduced Ruby/DL which allows to load shared libraries and call the provided functions from Ruby code. The Ruby/DL documentation shows how to import functions, how to work with and map Ruby to C types, etc. Ruby/DL also provides two way communication with callbacks, ie. it's possible to hand a Ruby block to a C function that expects a function pointer.

Rubinius introduced its own Foreign Function Interface (FFI) which resembles Ruby/DL, although FFI's API looks a bit different, eg. it uses Ruby symbols and array literals for type signatures instead of strings of C code or a custom type specifier formats as Ruby/DL does.

Earlier this year jruby-ffi, built on JNA, was introduced (JRuby doesn't have support for Ruby/DL).

While support on Rubinius and on JRuby was available, this still meant a large part of the Ruby world using MRI was using Ruby/DL or other ways to use shared libraries. To fix this, the ruby-ffi project was created by Wayne Meissner (who already created jruby-ffi) and now provides the same FFI interface as on Rubinius for JRuby, Ruby 1.8.x and Ruby 1.9.x. With this, it's possible to use the same Ruby code across all these Ruby implementations for accessing shared libraries.

Ruby FFI 0.2.0 is now available, installation is possible with gem install ffi. Documentation is available in the project's wiki, a good place to start is the Examples page. Charles Nutter provides some more explanation and samples of using FFI.

Rate this Article

Adoption
Style

Related Content

The InfoQ Newsletter

A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

We protect your privacy.

BT

AltStyle によって変換されたページ (->オリジナル) /