Category Archives: Jruby

Let’s start with the basic. What are bindings? It’s a way to call low level libraries (normally in C or C++) from another language (high level one, like ruby, java or whatever). This simple step requires two important things: 1) first, to know how we should call the method itself and 2) second, how to map the type from the high level language to C primitives types. To accomplish this, we have what is called foreign function interface which trivialize this task.

In ruby/jruby world we are gonna need ffi gem (jruby also has a compatible ffi gem), besides that the most important part is to have a clear interface in C. You can do bindings for a C++ library if you create a C interface first (because the bindings between C++ and C are free, the compiler knows how to do it by itself). So let’s cut the crap and write some code

So, if you have read until now, probably you just want something working, say no more. Download this tar.gz, and see all this by yourself. In the tar you have the code split into c/h cpp/hpp files as it should be, in the post I’ve put all together to simplify things. Just execute make test and if you have ruby, ffi gem and g++ installed on your system, you’ll see something like:

A few days ago after seeing this tweet, I’ve decided to migrate the gem rubygems-isit19 to jruby. Thanks to this, when you install another gem you’ll be able to read about compability of this gem with jruby, the information is fetched from isitjruby.com website.

Once you have installed the gem you will have two main features, it’s easier if I just show you. First the messages when you install gems:

$ jgem isitjruby faker
faker 0.3.1: http://isitjruby.com/faker
Blaxter says 0.3.1 works on GNU/Linux
it works perfectly, and it passes all test.
$ jgem isitjruby daemons
daemons 1.0.10: http://isitjruby.com/daemons
blaxter says 1.0 fails on GNU/Linux
Daemons use fork, jruby doesn't support fork, so it doesn't work and
never will

$ jgem isitjruby faker
faker 0.3.1: http://isitjruby.com/faker
Blaxter says 0.3.1 works on GNU/Linux
it works perfectly, and it passes all test.
$ jgem isitjruby daemons
daemons 1.0.10: http://isitjruby.com/daemons
blaxter says 1.0 fails on GNU/Linux
Daemons use fork, jruby doesn't support fork, so it doesn't work and
never will

And that’s it. The code is on github be free of fork me or open any issues. The important thing is populate with relevant information isitjruby.com for benefit of all jruby community. Oh I forgot to tell you how to install it, very easy, I’ve uploaded the gem to gemcutter so you can install it with something like

$ jgem install rubygems-isitjruby -s http://gemcutter.org

It’s also in github, but I think (and I hope) gemcutter will be the next rubyforge, so better gemcutter :).