home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / tcl / 1058 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  2.2 KB

  1. Path: sparky!uunet!usc!sdd.hp.com!elroy.jpl.nasa.gov!ames!agate!agate!adrianho
  2. From: adrianho@barkley.berkeley.edu (Adrian J Ho)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Re: How do I imbed tcl in an application
  5. Date: 28 Jul 92 09:07:58
  6. Organization: University of California, Berkeley
  7. Lines: 36
  8. Message-ID: <ADRIANHO.92Jul28090758@barkley.berkeley.edu>
  9. References: <1992Jul27.175107.7633@rchland.ibm.com>
  10.     <ADRIANHO.92Jul27175403@barkley.berkeley.edu>
  11.     <1992Jul28.114518.12123@rchland.ibm.com>
  12. NNTP-Posting-Host: barkley.berkeley.edu
  13. In-reply-to: shmdgljd@rchland.vnet.ibm.com's message of 28 Jul 92 11:45:18 GMT
  14.  
  15. In article <1992Jul28.114518.12123@rchland.ibm.com> shmdgljd@rchland.vnet.ibm.com (Jay Schmidgall) writes:
  16. >How do I provide access to structures more complex than just strings?
  17.  
  18. I was going to suggest arrays (vanilla Tcl) or keyed lists (Extended
  19. Tcl), but it sounds like...
  20.  
  21. >typedef struct {
  22. >    char *name;
  23. >    int  rank;
  24. >    int  ssn;
  25. >} Soldier;
  26. >Soldier grunt;
  27.  
  28. ...you want to preserve the struct in *this* form so that your
  29. internal code can mess around with it too.
  30.  
  31. >Now, is there any way I can pass ``grunt'' to a tcl proc and have it be
  32. >able to access grunt.name or grunt.rank ?
  33.  
  34. As you mentioned, you could add a tcl command whose sole purpose is to
  35. provide a Tcl interface to the appropriate fields, doing any necessary
  36. string conversions along the way.  Of course, this tends to blow up in
  37. your face if you have more than one struct type...
  38.  
  39. A good compromise (if you have Extended Tcl) is to use keyed lists.
  40. Support C functions to access and manipulate keyed lists are included,
  41. so you don't have to parse the keyed list yourself to extract the
  42. appropriate fields.  You'll have to remember the field types to do
  43. back conversions to numeric data, of course, but you'd have to do
  44. that anyways...
  45. --
  46. -----------------------------------------------------------------------------
  47. Adrian Ho, He With The Embarrassingly *Dead* Passion ** Phone: (510) 642-5563
  48. System Manager, CFD Lab, ME Dept, UC Berkeley * adrianho@barkley.berkeley.edu
  49. Maintainer, Tcl/Tk Contrib Archive ---- barkley.berkeley.edu [128.32.142.237]
  50.   Send all Tcl/Tk Archive-related stuff to tcl-archive@barkley.berkeley.edu
  51.