I am trying to rewrite a highly recursive function using inline C with Ruby. The function accepts an undefined number of arguments, i.e. it would look like this in Ruby:
def each_entity(*types)
# Do something and recurse.
end
I am trying to mimick this in inline C using the following code:
VALUE each_entity_c(int argc, VALUE *argv)
{
// ...
}
But this yields the compile error:
inline.rb:486:in `ruby2c': Unknown type "VALUE *" (ArgumentError)
Is this the correct way to accomplish this in C? If so, what could have caused this error? If not, how is it done?
Instead of using
builder.c
, trybuilder.c_raw
(orbuilder.c_raw_singleton
) when defining your methods. You might want to addVALUE self
to the end of the args list, but it seems to work with or without in my tests. It might also be worth explicitly specifying the arity, just to be safe:Using
builder.c
, Ruby Inline will rewrite the function so that it accepts RubyVALUE
types as parameters, and add code to convert these to the c types in your original. You're writing code that already expectsVALUE
arguments so don't want this conversion to be done, so you need to usec_raw
.