home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!sdd.hp.com!elroy.jpl.nasa.gov!ames!agate!agate!adrianho
- From: adrianho@barkley.berkeley.edu (Adrian J Ho)
- Newsgroups: comp.lang.tcl
- Subject: Re: How do I imbed tcl in an application
- Date: 28 Jul 92 09:07:58
- Organization: University of California, Berkeley
- Lines: 36
- Message-ID: <ADRIANHO.92Jul28090758@barkley.berkeley.edu>
- References: <1992Jul27.175107.7633@rchland.ibm.com>
- <ADRIANHO.92Jul27175403@barkley.berkeley.edu>
- <1992Jul28.114518.12123@rchland.ibm.com>
- NNTP-Posting-Host: barkley.berkeley.edu
- In-reply-to: shmdgljd@rchland.vnet.ibm.com's message of 28 Jul 92 11:45:18 GMT
-
- In article <1992Jul28.114518.12123@rchland.ibm.com> shmdgljd@rchland.vnet.ibm.com (Jay Schmidgall) writes:
- >How do I provide access to structures more complex than just strings?
-
- I was going to suggest arrays (vanilla Tcl) or keyed lists (Extended
- Tcl), but it sounds like...
-
- >typedef struct {
- > char *name;
- > int rank;
- > int ssn;
- >} Soldier;
- >Soldier grunt;
-
- ...you want to preserve the struct in *this* form so that your
- internal code can mess around with it too.
-
- >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 ?
-
- As you mentioned, you could add a tcl command whose sole purpose is to
- provide a Tcl interface to the appropriate fields, doing any necessary
- string conversions along the way. Of course, this tends to blow up in
- your face if you have more than one struct type...
-
- A good compromise (if you have Extended Tcl) is to use keyed lists.
- Support C functions to access and manipulate keyed lists are included,
- so you don't have to parse the keyed list yourself to extract the
- appropriate fields. You'll have to remember the field types to do
- back conversions to numeric data, of course, but you'd have to do
- that anyways...
- --
- -----------------------------------------------------------------------------
- Adrian Ho, He With The Embarrassingly *Dead* Passion ** Phone: (510) 642-5563
- System Manager, CFD Lab, ME Dept, UC Berkeley * adrianho@barkley.berkeley.edu
- Maintainer, Tcl/Tk Contrib Archive ---- barkley.berkeley.edu [128.32.142.237]
- Send all Tcl/Tk Archive-related stuff to tcl-archive@barkley.berkeley.edu
-