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

===============================================================================

This should work:

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

  Sean O'Dell

···

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...

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?

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

Oops, try:

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

  Sean O'Dell

···

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"));

bingo. that solve's problem one.

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

-a

···

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

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

--

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

===============================================================================

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_class_new_instance() instead.

  return rb_class_new_instance(1, rb_str_new2("filename"), rb_cFile);

···

--
Nobu Nakada

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

···

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

--

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

===============================================================================

Hi,

At Tue, 22 Jun 2004 07:13:13 +0900,
Ara.T.Howard wrote in [ruby-talk:104293]:

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

Not provided publicly. See prep_stdio() in io.c.

···

--
Nobu Nakada

Typing too fast again, you're right.

  Sean O'Dell

···

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").

Since in C you don't have access to all of the C functions that implement
every method in every class, 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

···

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?

thank you.

-a

···

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

Hi,

At Tue, 22 Jun 2004 07:13:13 +0900,
Ara.T.Howard wrote in [ruby-talk:104293]:

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

Not provided publicly. See prep_stdio() in io.c.

--
Nobu Nakada

--

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

===============================================================================