Re: [rice] Ruby wrapper for the Firebird SQL C++ API
- Jason Roelofs
- 2011-12-10 @ 17:07
On Dec 9, 2011, at 7:59 PM, Pierre Y. wrote:
> Hi all,
> The Firebird SQL  project team is working on the new Firebird 3
> version  that will be out at the end of next year. They will
> provide a fresh new C++ API and I want to write a new Ruby driver for
> Firebird using this API.
> An example of use of this API in C++ has been made by one of the core
> team member and is here 
> Somebody told me about RICE to create Ruby wrapper around C++ code.
> But I don't know where to start. What I know is that the "old/legacy"
> Firebird C API in libfbclient.so now exposes a new function called
> "fb_get_master_interface" that returns an instance of a pure virtual
> C++ class called IMaster from where everything in the new API is
> accessible. Instance of classes that will be returned from IMaster are
> refcounted and they are all pure virtual classes.
> The header files for the pure virtual classes are here 
> My questions : Is RICE the right tool to wrap this kind of API ? Do
> you have an example of code from where I could start ? I'm more a
> "Delphi/Windows" developer and quite good at Ruby but not so much
> fluent with C++ and Ruby extensions/gems.
> Many thanks for your help, regards,
> Pierre Yager
>  http://firebirdsql.org
>  https://github.com/asfernandes/firebird
>  https://github.com/asfernandes/fbstuff
>  https://github.com/asfernandes/firebird/tree/master/src/include/firebird
I guess first and foremost using Rice does require a pretty good
understanding of C++. Looking through the header files, I didn't see
anything that gave me immediate pause in terms of complexity of wrapping,
though because all of the classes are pure virtual you will need to hook
up a Rice::Director for every one of the classes, as Ruby needs concrete
code and you can't automatically virtual call yourself into C from C++.
If you're not the most comfortable with C++, particularly the more
advanced concepts, I would recommend first trying to wrap this up with
SWIG and see how far you can get with that tool.
Almost all of the relevant Rice documentation is in the README:
http://rice.rubyforge.org/. Rice::Director is about 3/4 the way down the
Let me know if you have more specific questions, it's hard to say more
without actually diving in and trying to build up a wrapper.