tags:

views:

224

answers:

2

I have a C program in which I create a tcl interpreter. I then open a file in the C program and want to pass it onto the tcl interpreter so the tcl interpreter can do I/O on it.

And I realize I could just open the file in the tcl interpreter, but I get an open file descriptor some somewhere else, so that's not an option, unfortunately.

Any ideas or tricks, or did I miss something in the tcl C API?

+1  A: 
man Tcl_MakeFileChannel

Read there about Tcl_MakeFileChannel and Tcl_RegisterChannel

msorc
I saw chan command doc at tcl level, but I didn't see anything that appeared appropriate for doing this. I simplified the problem. Actually, I am using the Perl Tcl module and need to construct a tcl command to do the same thing. Is there an equivalent way to do this via the tcl "chan" operation? Because file is opened in Perl, but I can access file descriptor, and need to connect this into the tcl subsystem. But if there isn't, I'll bite the bullet and do it in C this way. Thanks for the tip!
xcramps
Could you write a TCL C extension to create a new TCL command that does what you need using the Tcl_MakeFileChannel and Tcl_RegisterChannel API functions?
Jackson
I do think these tips are the way you need to go. Tcl_MakeFileChannel takes an existing file handle and makes it available in Tcl. Read the documentation thoroughly. I have not worked with combining Perl and Tcl, so I can't give any specific tips for that.
Michael Mathews
A: 

Wouldn't have have to open the file before you create the tcl interpreter process, if it's going to have the file descriptor have meaning?

If you open after, and say in the C program you have file descriptor 9, and you then pass this 9 to the tcl interpreter process, that 9's not going to mean anything.

smcameron
This comment would apply if he was running Tcl as a separate process, but I think he has a Tcl interpreter embedded in the C program, ie. in the same process.
Colin Macleod