From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-06-06T08:22:02+09:00 Subject: Re: Ruby-SWIG question: wrapping function objects with blocks >> On Thu, 05 Jun 2003 17:07:03 +0200, Christian Szegedy wrote: >> >>> In out project, there are a lot of functions which >>> take a function object parameter (Apply) >>> and call then may call the call method of this >>> object. I would like to wrap it with a Ruby code >>> which takes a block and the creates a new apply >>> object whose call function calls the block. OK.. I did it without SWIG.. tell me if you can use it ? > ls CVS/ example.c extconf.rb test.rb > ruby extconf.rb && gmake creating Makefile gcc -fPIC -g -O2 -I. -I/home/neoneye/stow/ruby18_r2/lib/ruby/1.8/i386-freebsd5.0 -I/home/neoneye/stow/ruby18_r2/lib/ruby/1.8/i386-freebsd5.0 -I. -c example.c gcc -shared -rdynamic -Wl,-soname, -L"/home/neoneye/stow/ruby18_r2/lib" -o Example.so example.o -lcrypt -lm -lc > ruby test.rb before proc after before yield after > cat test.rb require 'Example' test_hook = Proc.new do puts "proc" end test(test_hook) def xtest p = Proc.new do yield end test(p) end xtest do puts "yield" end > cat example.c #include #include /* def test(hook); hook.call; end */ VALUE wrap_test(VALUE self, VALUE hook) { printf("before\n"); rb_funcall(hook, rb_intern("call"), 0); printf("after\n"); return Qnil; } int Init_Example() { rb_define_global_function("test", wrap_test, 1); return 0; } > cat extconf.rb require 'mkmf' create_makefile("Example") > -- Simon Strandgaard