Subject:
Re: [ruby-ffi] attach_function a bit draconian
From:
Matijs van Zuijlen
Date:
9/5/11 2:10 AM
To:
ruby-ffi@googlegroups.com

Hi Charlie,

On 04/09/2011 23:19, cfis wrote:
I've written a ffi wrapper for the free image library, which is here:

http://cfis.github.com/free-image-ruby/

The problem is that I've coded against the latest version of
FreeImage, and most linux distributions have older versions
installed.  Thus when I try to load the gem it fails since
attach_function throws an error because the older versions don't have
all the functions.

You can just wrap the call to attach_function in a begin-rescue-end construct. Then in the rescue block, you can do whatever you want. In your case, this would probably mean issuing a warning and then defining a stub function. You can even wrap that in a method, say, attach_function_safely.

Regards,
Matijs