From: Tobias Peters Date: 2002-04-05T17:33:44+09:00 Subject: Re: Help: Ruby<->C++ callbacks On Thu, 4 Apr 2002, Luigi Ballabio wrote: > >There is no need for this Callback class. > > Yes, there is. Here is the full picture, as much simplified as possible. No. It might be convenient for you to introduce this class, because you want to use swig to do the wrapping, but the resulting ruby programming interface would be ugly. Your method that expects a Callback should also accept a block instead. You can easily add this feature in native ruby after you created your wrapper with swig: # File: cpplib.rb require "cpplib.so" class Callback_Taker alias cpp_add_callback add_callback def add_callback(*args, &block) if (block) cpp_add_callback(Callback.new(block)) elsif (args.size > 0) cpp_add_callback(args[0]) end end end and let your users require "cpplib", which will prefer "cpplib.rb" over "cpplib.so". > I'm not writing a C++ extension from scratch: I'm writing bindings for an > existing C++ library. which library? Tobias