Logan Capaldo wrote:
> On Thu, Apr 12, 2007 at 10:07:52AM +0900, David Simas wrote:
>>
>> I'm trying to write an extension to access some C++ libraries from
>> Ruby (1.8.4).  One of the C++ functions uses a reference to pass
>> a value back to the caller as a side effect:
>>
>>    ErrorHandle* DetectInvisibleWatermark(const char *inputfilename,
>> 					const char *wmfilename,
>> 					float horizOffset,
>> 					float vertOffset,
>> 					float lowPassFilterFactor,
>> 			      	 	float &modulationStrength,
>> 					const char *key, const char *seed,
>> 					const char *outfilename);
>>
>> (N.B.: "float &modulationStrength")
> Wrap it in a C function
> void foo(float* bar) {
>    baz(*bar);
> }
> 
> void baz(float& quux) {
>   quux /= 1.5;
> }

There's still the question of how to get both return values back to the 
caller. It depends on how you want to use the function from ruby. You 
could return both the ErrorHandle and a float, as a two element array (a 
ruby array, that is). The caller can then unpack them like this:

err_h, mod_str = wrap_DetectInvisibleWatermark(...)

Or you could return one and yield the other (a good choice if one is 
less likely to be used).

Or maybe return the float (as a ruby float, of course) and rb_raise() if 
there is a nonzero ErrorHandle* .

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407