On Apr 4, 2005 8:34 AM, Charles Mills <cmills / freeshell.org> wrote: > > > Are there any general rules of thumb that you use when writing > extensions? > > http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/47700 > > You shouldn't be able to cause your extension to seg fault from Ruby. > That may sound like a joke, but I just mean using StringValue, > NUM2LONG, etc before you starting using Ruby objects in C. > > > > > My first problem was trying to figure out what should remain Ruby > code > > and what should be moved out to C. For example, if I opened the file > > that contained binary data in Ruby, how could I "get" to that data > > using a FILE pointer in C? Or should I just pass the filename to the > > C extension? > > > You can do either. IMO it depends on the layout of the file. If your > reading line by line you can do this easily using the rb_io_* functions > found in intern.h. If your going to be moving the file position > around, using fgetc/ungetc, or reading into C structs it may be easier > to use the stdio functions directly. > > -Charlie So, if I have a IO object in Ruby, how could I use C's stdio functions on it? And how could I have figured it out without asking the mailing list? :-) Cuz I'm sure I'll have lots more questions. Thanks, Joe