home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!dssv01!kennykb
- From: kennykb@dssv01.crd.ge.com (Kevin B. Kenny)
- Newsgroups: comp.lang.tcl
- Subject: Re: How do I imbed tcl in an application
- Message-ID: <1992Jul28.172714.25136@crd.ge.com>
- Date: 28 Jul 92 17:27:14 GMT
- References: <1992Jul27.175107.7633@rchland.ibm.com> <ADRIANHO.92Jul27175403@barkley.berkeley.edu> <1992Jul28.114518.12123@rchland.ibm.com>
- Sender: usenet@crd.ge.com (Required for NNTP)
- Reply-To: kennykb@crd.ge.com
- Organization: GE R&D, Information Architectures & Management Program
- Lines: 72
- Nntp-Posting-Host: dssv01.crd.ge.com
-
-
- In article <1992Jul28.114518.12123@rchland.ibm.com> you write:
- |> Question 2: (long winded, sorry)
- |>
- |> How do I provide access to structures more complex than just strings?
- |>
- |> For example, I've got a structure
- |>
- |> typedef struct {
- |> char *name;
- |> int rank;
- |> int ssn;
- |> } Soldier;
- |>
- |> Soldier grunt;
- |>
- |> Now, is there any way I can pass ``grunt'' to a tcl proc and have it be
- |> able to access grunt.name or grunt.rank ?
-
- My preference is to have a single Tcl function that represents an
- object. For instance, in the tclTCP package, there is a command,
-
- tcp server
-
- that creates a TCP server object. One of the side effects to `tcp
- server' is that it creates a new Tcl command, with a name like
- `tcp_server_4', and returns its name. The data structure describing
- the server is allocated from free store and initialized, and carried
- along as the command's client data. That way, I can say
-
- set s [tcp server]
-
- and then say things like
-
- # Begin accepting connections
- $s start
- # Tell the user what port we're listening to
- puts stdout "Server is listening at [$s configure -port]"
-
- ... and so on. If you want to see some more coding examples, ftp the
- tclTCP package from barkley.berkeley.edu.
-
- Extended Tcl uses a competing approach, owing primarily to personal
- taste (Karl Lehenbauer doesn't care for the noun-verb syntax that the
- use of the client data enforces, while I prefer it). It has an
- additional type of object called a `handle' that provides a textual
- reference to the data structures. If you ftp Extended Tcl from
- barkley.berkeley.edu, you'll find a file called `Handle.man' in the
- `man' directory that describes the C rountines that Extended Tcl uses
- to map between structure pointers and textual names.
-
- If I had done tclTCP the latter way, the syntax would have looked
- like:
-
- set s [tcp create_server]
- # Start accepting new connections
- server start $s
- # Tell the user the listening port
- puts stdout "Server listening at port [server configure $s -port]"
-
- ... and so on. The code would also have been a trifle more
- complicated, because the handles would have to be converted to
- pointers explicitly, rather than having Tcl_Eval just look up a client
- data word. As I said, which method to choose is largely a matter of
- personal taste.
-
- John Ousterhout has experimented with both methods: files in Tcl are
- identified by handles, while widgets in Tk are independent commands
- having client data. John, do you have anything to add about the
- tradeoffs?
-
- 73 de ke9tv/2, Kevin There isn't any .signature virus, is there?
-