> Programming Languages > Ruby
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Ruby



Ruby - "opening a file in ext" in Programming Languages


Old 06-21-2004   #1
..a.T.Howa..
 
Default opening a file in ext


what's the correct way to do this? i'm poking around in file.c now - no
File.new to be found... IO.open perhaps? i need to return an open file from
a c function...

cheers.

-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it; and a weed grows, even though we do
| not love it. --Dogen
================================================== =============================
 
Old 06-21-2004   #2
.... ..De..
 
Default Re: opening a file in ext

On Monday 21 June 2004 14:23, Ara.T.Howard wrote:
> what's the correct way to do this? i'm poking around in file.c now - no
> File.new to be found... IO.open perhaps? i need to return an open file
> from a c function...


This should work:

return rb_funcall(rb_cFile, rb_intern(":new"), rb_str_new2("filename"));

Sean O'Dell


 
Old 06-21-2004   #3
.... ..De..
 
Default Re: opening a file in ext

On Monday 21 June 2004 14:25, Sean O'Dell wrote:
>
> This should work:
>
> return rb_funcall(rb_cFile, rb_intern(":new"), rb_str_new2("filename"));


Oops, try:

return rb_funcall(rb_cFile, rb_intern(":new"), 1, rb_str_new2("filename"));

Sean O'Dell


 
Old 06-21-2004   #4
..a.T.Howa..
 
Default Re: opening a file in ext

On Tue, 22 Jun 2004, Sean O'Dell wrote:

> On Monday 21 June 2004 14:25, Sean O'Dell wrote:
>>
>> This should work:
>>
>> return rb_funcall(rb_cFile, rb_intern(":new"), rb_str_new2("filename"));

>
> Oops, try:
>
> return rb_funcall(rb_cFile, rb_intern(":new"), 1, rb_str_new2("filename"));
>
> Sean O'Dell


hmmm. is this really the best way? i mean, why not call the dispatched to
method directly? i suppose this insulates you from name changes - but it
seems like one should be to call it directly doesn't it?

cheers.

-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it; and a weed grows, even though we do
| not love it. --Dogen
================================================== =============================
 
Old 06-21-2004   #5
..bu...ka.. ..fthome.n..
 
Default Re: opening a file in ext

Hi,

At Tue, 22 Jun 2004 06:26:39 +0900,
Sean O'Dell wrote in [ruby-talk:104279]:
> > This should work:
> >
> > return rb_funcall(rb_cFile, rb_intern(":new"), rb_str_new2("filename"));

>
> Oops, try:
>
> return rb_funcall(rb_cFile, rb_intern(":new"), 1, rb_str_new2("filename"));


rb_intern(":new") differs from rb_intern("new").

You also can use rb_cl***_new_instance() instead.

return rb_cl***_new_instance(1, rb_str_new2("filename"), rb_cFile);

--
Nobu Nakada


 
Old 06-21-2004   #6
..m ..nt..
 
Default Re: opening a file in ext

Ara.T.Howard wrote:

>
> what's the correct way to do this? i'm poking around in file.c now - no
> File.new to be found... IO.open perhaps? i need to return an open file
> from a c function...
>

Hmmm...do you want MakeOpenFile() from rubyio.h?

 
Old 06-21-2004   #7
..bu...ka.. ..fthome.n..
 
Default Re: opening a file in ext

Hi,

At Tue, 22 Jun 2004 06:23:13 +0900,
Ara.T.Howard wrote in [ruby-talk:104277]:
> what's the correct way to do this? i'm poking around in file.c now - no
> File.new to be found... IO.open perhaps? i need to return an open file from
> a c function...


You should see io.c.

VALUE rb_file_open(const char *fname, const char *mode);
VALUE rb_file_sysopen(const char *fname, int flags, int mode);

Hmmm, but rb_file_sysopen() lacks the prototype...

--
Nobu Nakada


 
Old 06-22-2004   #8
.... ..De..
 
Default Re: opening a file in ext

On Monday 21 June 2004 14:37, nobu.nokada@softhome.net wrote:
> Hi,
>
> At Tue, 22 Jun 2004 06:26:39 +0900,
>
> Sean O'Dell wrote in [ruby-talk:104279]:
> > > This should work:
> > >
> > > return rb_funcall(rb_cFile, rb_intern(":new"),
> > > rb_str_new2("filename"));

> >
> > Oops, try:
> >
> > return rb_funcall(rb_cFile, rb_intern(":new"), 1,
> > rb_str_new2("filename"));

>
> rb_intern(":new") differs from rb_intern("new").


Typing too fast again, you're right.

Sean O'Dell


 
Old 06-22-2004   #9
.... ..De..
 
Default Re: opening a file in ext

On Monday 21 June 2004 14:43, Ara.T.Howard wrote:
> On Tue, 22 Jun 2004, Sean O'Dell wrote:
> > On Monday 21 June 2004 14:25, Sean O'Dell wrote:
> >> This should work:
> >>
> >> return rb_funcall(rb_cFile, rb_intern(":new"), rb_str_new2("filename"));

> >
> > Oops, try:
> >
> > return rb_funcall(rb_cFile, rb_intern(":new"), 1,
> > rb_str_new2("filename"));
> >
> > Sean O'Dell

>
> hmmm. is this really the best way? i mean, why not call the dispatched to
> method directly? i suppose this insulates you from name changes - but it
> seems like one should be to call it directly doesn't it?


Since in C you don't have access to all of the C functions that implement
every method in every cl***, it's simply the most consistent way to make the
call. If you know the actual C function name, I'm sure you could call that
directly.

Sean O'Dell


 
Old 06-22-2004   #10
..a.T.Howa..
 
Default Re: opening a file in ext

On Tue, 22 Jun 2004 nobu.nokada@softhome.net wrote:


> VALUE rb_file_open(const char *fname, const char *mode);


bingo. that solve's problem one.

problem two - correct way for turning a FILE *filep into a rb_cFile;

-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it; and a weed grows, even though we do
| not love it. --Dogen
================================================== =============================
 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0