Subject:
[ruby-ffi] Re: attach_function a bit draconian
From:
cfis
Date:
9/4/11 6:19 PM
To:
ruby-ffi

Thinking about this a bit more, maybe another approach is to explicity
support version sin FFI.  So:

attach_function(:new_function, [], :int, :version => '1.1')

Then:

module FFI
module Library  def

On Sep 4, 3:19 pm, cfis <c...@savagexi.com> 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.
>
> This isn't what I want - the older versions work perfectly fine, they
> just don't include as much functionality.  So instead of blowing up, I
> would prefer if FFI throw a warning message but continue loading the
> library.
>
> If a user does call one of these unimplemented functions, then FFI
> should throw an error and allows the wrapping library to customize
> that message to say something useful (sorry, to use this function you
> need to upgrade to a newer version of freeimage).
>
> I can think of lots of ways of doing this, here is one possibility:
>
> * If a function is not implemented, instead of throwing an error, wrap
> it with a NotImplemented function (to go along with Function and
> Variadic).
>
> * When a NotImplemented function is called, throw an error.  This
> could:
>     - Just hard-code an error, not allow customization
>     - Call a method on library, not_implemented, that developers could
> override
>     - Call a proc which would be passed to attach_function which would
> be called
>
> I lean towards the 2nd choice, but don't feel very strongly about it.
>
> Does this sound like an idea that could be accepted to FFI?  If so,
> I'll code up a patch for review.
>
> Thanks - Charlie