Subject: Re: [ruby-ffi] attach_function a bit draconian |
From: Colby Gutierrez-Kraybill |
Date: 9/5/11 2:45 PM |
To: ruby-ffi@googlegroups.com |
On Sep 5, 2011, at 12:10 AM, Matijs van Zuijlen wrote:
Hi Charlie, On 04/09/2011 23:19, cfis wrote: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.I've written a ffi wrapper for the free image library, which is here: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
this++ I had a need to create convenience aliases for GSL routines and I created a new method that wrapped around attach_function as well as a side-along override of method_missing: By using method_missing, you could capture any calls that a developer expects to be in the library (a more current one) and do exactly what you need doing. See: attach_gsl_function, http://gsl4r.rubyforge.org/git?p=gsl4r.git;a=blob;f=lib/gsl4r/util.rb;h=3c2ce22ac866b5053b8fed7a34058e299950eae5;hb=HEAD and http://shrewdraven.org/content/automatically-generated-method-aliases-gsl4r