From: Ralph B. <ra...@de...> - 2005-07-16 10:45:03
|
Thanks Jonathan! I was able to get it to work. If at all possible I would prefer not to link my C++ stuff against Ruby in order to keep it clean. It is a library meant for stand-alone distribution. I now handle the conversion in the SWIG layer: // Convert bool from Ruby --> C with type check %typemap(in) BitmapPointer { id ocobj = (id) NUM2UINT( rb_funcall($input, rb_intern("__ocid__"), 0) ); $1 = [(NSBitmapImageRep*) ocobj bitmapData]; } Three more things were needed to make it work. 1. Testinterface::Test(bitmapRep.bitmapData()) -> Testinterface::Test(bitmapRep) (duh) 2. #include <AppKit/NSBitmapImageRep.h> (in the SWIG .i file) 3. You're now mixing Objective-C and C/C++ (aptly termed Objective-C++), and the compiler needs to be made aware of this. This is done by changing the extension of the *_wrap.cxx file to .mm, ie. *_wrap.mm. Update your makefile. Thanks again, Jonathan. Ralph On Jul 15, 2005, at 00:52, Jonathan Paisley wrote: > On 14 Jul 2005, at 21:08, Ralph Brorsen wrote: > >> The main event here is of course "$1 = StringValuePtr($input);", >> which should, as I understand it return a char pointer to the string >> data which bitmapRep.bitmapData() returned. The reason it is >> converted to a Ruby string, I assume, is because RubyCocoa sees the >> char *, and thinks it is a string. Perhaps the string is copied to an >> internal buffer? > > As you've identified, the return value of bitmapData is being > converted to a ruby string. The easiest solution (since you're already > dealing with some native code) may be to pass the NSBitmapImageRep > pointer to your native code and get the pointer to the bitmapData from > within your native code. |