[Ruby] splatting arguments in a C extension
Ryan Davis
ryand-ruby at zenspider.com
Sat Feb 2 00:46:59 PST 2008
On Feb 1, 2008, at 22:53 , Aaron Patterson wrote:
> The function is defined in ruby, and I'm calling it from C. I need
> to get the rb_funcall to splat my args (heh).
I'm not sure you can. If it is possible, splat the arg on the ruby
end. The following works:
require 'rubygems'
require 'inline'
class X
def m *args
p(*args)
end
inline do |builder|
builder.c '
void x(VALUE ary) {
rb_funcall(self, rb_intern("m"), 1, ary);
}
'
end
end
X.new.x([1, 2, 3])
Other variations I've tried (without *args on the ruby side) don't
work. I've been grepping around the ruby source looking for something
and come up blank. I suppose I should read the source for rb_funcall
straight up.
More information about the Ruby
mailing list