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:

One of the awesome things about dealing with open software is to be able to access to the source code. When you deal with complex systems (so, every fraking day normally) the worst thing are black boxes that you cannot see, check or change their inside. This black boxes use to be closed/privaty systems/libraries/whatever. Lucky we are, android is open source you can get the source easily with repo but for developing applications in eclipse you can just install Android sources plugin and that’s it, really nice.

I honestly don’t know why I still use ubuntu, it pisses me off a lot with so many useless change related to its user interface, very pretty (the first 2 minutes) but totally useless. At least it’s easy to change this stuff. To go back to the typical scrollbar just execute this in a console: