home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / hypercar / 4231 < prev    next >
Encoding:
Text File  |  1992-11-18  |  4.5 KB  |  94 lines

  1. Newsgroups: comp.sys.mac.hypercard
  2. Path: sparky!uunet!pageworks.com!world!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!apple!mumbo.apple.com!gallant.apple.com!delos.apple.com!user
  3. From: shebs@apple.com (Stan Shebs)
  4. Subject: Re: Word 5.1 & AppleEvents (actually AppleScript)
  5. Sender: news@gallant.apple.com
  6. Message-ID: <shebs-181192090751@delos.apple.com>
  7. Date: Wed, 18 Nov 1992 18:22:32 GMT
  8. References: <1992Nov11.232622.30978@fourd.com> <7875@lib.tmc.edu> <shebs-171192100253@delos.apple.com> <jpugh-171192132944@wolverine.apple.com> <1992Nov18.171125.12285@waikato.ac.nz>
  9. Organization: Apple Computer Inc.
  10. Followup-To: comp.sys.mac.hypercard, comp.sys.mac.programmer
  11. Lines: 81
  12.  
  13. In article <1992Nov18.171125.12285@waikato.ac.nz>, ldo@waikato.ac.nz
  14. (Lawrence D'Oliveiro, Waikato University) wrote:
  15. > In article <jpugh-171192132944@wolverine.apple.com>, jpugh@apple.com (Jon Pugh) writes:
  16. > > [...] I would like to point out that
  17. > > a lot of the design decisions were made for compatibility reasons.
  18. > > AppleScript would like to be a full OOP language, but it has to be
  19. > > implemented in non-OOP programs.
  20. > Why? AppleScript is a language in its own right, right? So how would you
  21. > embed AppleScript code inside programs written in other languages? It seems
  22. > to me the natural way would be to store AppleScript sequences (possibly in some
  23. > "tokenized" or other such "pseudocompiled" form) in resources or suchlike.
  24. > So why should that have any interaction with the language that the rest of the
  25. > program is written in?
  26. > > That makes it very tough to hide the implementation details.
  27.  
  28. The OSA interface is the basis for talking to a script engine.  For
  29. instance, it allows you to do something like this in your source code:
  30.  
  31.          sprintf(buf, "((%d - 32) * 5) / 9 ", fahr);
  32.          rslt = OSAExecute(buf);
  33.  
  34. and get a result, in case implementing your own converter is hard to do
  35. :-).
  36. Perhaps a better example would be 
  37.  
  38.          sprintf(buf, "next move of white given %s",
  39. chess_board_in_ascii());
  40.          rslt = OSAExecute(buf);
  41.  
  42. where the "next move" handler connects to a chess-playing program.  Note
  43. that for both of these examples, the script can do its work without
  44. knowing anything more than what's passed to it.  Unfortunately, this
  45. only handles a small percentage of what one might want to do with scripts.
  46.  
  47. As a more realistic example, suppose you've acquired a cool tiling
  48. script that, given a collection of windows, moves and sizes them to be
  49. non-overlapping, and that your app has a "Tile Windows" menu item to attach
  50. the script to.  Then you could write something like
  51.  
  52.                                 ...
  53.                                 case miTileWindows:
  54.           OSAExecute("tile windows of application \"xxx\");
  55.           break;
  56.         ...
  57.  
  58. where xxx is filled in by your app.  How does the script collect the sizes
  59. and positions of your windows and then tell the application how to change
  60. them?  Plan A would be to implement a special AppleEvent that passes back a
  61. list of window ids, resizeabilities, and dimensions, something like
  62.  
  63.         {{1, true, 30, 30, 400, 500}, {2, false, 200, 100, 300, 452}}
  64.  
  65. and then have the script dissect the list in classic Lisp fashion.  This
  66. is pretty inefficient and inflexible though, especially for an application
  67. more complicated than TeachText.  An application that supports the object
  68. model allows you to ask for just the "position" property of a "window"
  69. object and get back, say, {400, 500}, and you only need to do that for the
  70. windows whose "resizeable" property was "true".  So with Plan B, your
  71. application only defines event handlers for accesses to windows and their
  72. properties, while the script engine handles the composing of events that
  73. acquire or modify those properties.  This is actually simpler and *more*
  74. efficient than trying to define huge numbers of event types! (plus Jon
  75. is happier because he has fewer types of events he has to register :-) )
  76.  
  77. One significant advantage of the AE object model is that you can
  78. implement the objects of your application in *any* way you so desire.
  79. You don't have to make anything elaborate, in fact using the refCon
  80. field of a window for an object id works perfectly well.  As long as
  81. your application makes it *appear* as though it has window objects,
  82. the rest of the AE world is happy.
  83.  
  84. For an idea of what a full object model can buy you, look at the latest
  85. Filemaker Pro(tm, no doubt), which not only has lots of classes and
  86. properties, but it documents them very nicely with a Filemaker database!
  87.  
  88. Stan Shebs
  89. Apple ATG System Software
  90. shebs@apple.com
  91.