Ruby lnline question

Dear all,

I’d like to have Ruby Inline create a Ruby method from the
following C code:

#include <stdio.h>

int main(int argc, char *argv[])
{
int x;
printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

(so that I can enter a variable number of arguments and have these
returned.)

Now I tried:

#!/usr/local/bin/ruby -w

require ‘rubygems’
require ‘inline’

class Example
inline(:C) do |builder|
builder.c ‘int main(int argc,char *argv[])
{
int x;
printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}’
end
end

p Example.new.main(3,‘a’,‘b’,‘c’)

but got:

WARNING: ‘char * argv[]’ not understood
i.rb: In function ‘main’:
i.rb:15: error: ‘argv’ undeclared (first use in this function)
i.rb:15: error: (Each undeclared identifier is reported only once
i.rb:15: error: for each function it appears in.)
i.rb:9: warning: return type of ‘main’ is not ‘int’
/usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:402:in
build': error executing gcc -shared -fPIC -g -O2 -I /usr/local/lib/ruby/1.8/x86_64-linux -I /usr/local/include -o "/home/axel/.ruby_inline/Inline_Example_fad5.so" "/home/axel/.ruby_inline/Inline_Example_fad5.c" : 256 (CompilationError) Renamed /home/axel/.ruby_inline/Inline_Example_fad5.c to /home/axel/.ruby_inline/Inline_Example_fad5.c.bad from /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:679:ininline’
from i.rb:7

What am I missing ?

Thank you very much.

Best regards,

Axel

Quoth Axel E.:

printf("%d\n",argc);

#!/usr/local/bin/ruby -w
for (x=0; x<argc; x++)
ERRORS!

What am I missing ?

Thank you very much.

Best regards,

Axel

This isn’t how RubyInline is supposed to be used. RubyInline is mostly
for
functions with a defined number of arguments AFAIK. It will infer the
correct
ruby type <-> C type conversion automatically for you for that, but I
don’t
think it does varargs.

Furthermore, if you were writing a C ruby extension with a varargs
function,
the signature is:

VALUE func(int argc, VALUE *argv, VALUE obj)

(Where argc is the actual number of arguments, argv is the C array of
the
arguments, and obj is the receiver (quoting README.EXT from Ruby
source).)

HTH,