opening a file in ext

A

Ara.T.Howard

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
===============================================================================
 
S

Sean O'Dell

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
 
S

Sean O'Dell

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
 
A

Ara.T.Howard

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
===============================================================================
 
N

nobu.nokada

Hi,

At Tue, 22 Jun 2004 06:26:39 +0900,
Sean O'Dell wrote in [ruby-talk:104279]:
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);
 
T

Tim Hunter

Ara.T.Howard said:
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?
 
N

nobu.nokada

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

Sean O'Dell

Hi,

At Tue, 22 Jun 2004 06:26:39 +0900,

Sean O'Dell wrote in [ruby-talk:104279]:
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
 
S

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

Ara.T.Howard

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
===============================================================================
 
N

nobu.nokada

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

Ara.T.Howard

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.

thank you.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ext portability question 5
tk tabbed pane 1
Data_Wrap_Struct (cKlass, 0, 0, ptr); 1
irb 5
openssl examples and docs 12
stable-snapshot.tgz 1
latest instiki err 2
determining ruby interpreter 4

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top