From: Cooper Stevenson Date: 2006-08-07T07:05:13+09:00 Subject: Re: Ruby Newbie: Simple C Wrappers? > If so, write a small wrapper like > > VALUE rb_main(VALUE self, VALUE args) [snip] Thanks, Simon. I'm working on this now! I'm trying to run this C application and capture the user's input and output to a Ruby string array. This way, I can use the values via Ruby on Rails to display content based on what's going on with the C application. Thanks again! -Cooper Simon Kr�ger wrote: > Cooper Stevenson wrote: >> Hello, >> >> ... >> I would like to interface what seems to be a straightforward main >> program (as I understand it that's all I need to interface, not the rest >> of the .c files, please correct me if this is in error) and have >> achieved a compile with an empty Init function like so: >> >> void >> Init_jzipr() >> { >> >> } >> >> irb works: >> >> $ irb >> irb(main):001:0> require 'jzipr' >> => true >> >> I am finding the next step--creating the class--difficult. Here's >> jzip.c--it's doesn't look like much but doing it for the first time... > > What are you trying to achieve? > Do you want to start the main function from ruby? > (I don't see the benefit here, just shell out to the program) > > If so, write a small wrapper like > > VALUE rb_main(VALUE self, VALUE args) > { > // you could/should use args here to build up a C array with parameters > main(0, 0); > return self; > } > > and call rb_define_method in your Init_jzipr to make that method available > in ruby. > > void > Init_jzipr() > { > rb_define_method(rb_cObject, "main", rb_main, -2) > } > > cheers > > Simon >