From: Joel VanderWerf Date: 2007-09-23T05:19:37+09:00 Subject: Re: [ANN] CplusRuby - Gluing C and Ruby Michael Neumann wrote: > In the example you give I only see one minor difference. In CplusRuby, > method :stimulate can be called directly from the C-side, without > NUM2DBL conversions of Ruby-types. That's very important for my > usage scenario. > But I think you can do the same with cgen. Actually, I don't think cgen has that feature.... one of the things I'll have to er, borrow, from cplusruby. Currently the only way to do this is to define a separate C function that the method calls. Reading the cplusruby .c output, it looks like there is an outer function (Neuron_call__stimulate) that accepts ruby value arguments, and then converts them and calls an inner function (Neuron__stimulate), which expects C-typed arguments. You could do this in cgen by using define_c_method to define the outer function and define_c_function to define the inner function. I guess I was used to performing the conversion manually, so I never added that feature as a convenience. I can see that it would be more of a necessity than a convenience if the function needed to be called from C as well as ruby. The selfc->stimulate function pointer is another difference, and necessary for the same reason, I guess. In a cshadow struct, this struct member doesn't exist, but there is reference ("VALUE self;") back to the original object, on which you can call methods (with the additional friction of type conversions, if the caller is native C code). The fact that you have pointers to functions that accept C-typed args makes access from C easy and efficient, but it also uses a lot of space in the struct with a pointer to each function that implements a method. What about having a unique struct for each class that keeps these pointers, and then the struct only needs a pointer to this "singleton"? -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407