[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What?



In article <nsp4-97AFEB.10200211082002@news2.news.adelphia.net>,
 mw <nsp4@mac.com> wrote:

> For example, how would you make Macintosh API calls in this language?

The same as in any non-C language these days: by calling out to C 
functions.

The Gwydion Dylan distribution contains (somewhat sketchy) Carbon 
interfaces, and some example programs e.g. a Dylan version of SillyBalls:

author: Gareth Baker and Rob Myers yarrel @netscape.net
synopsis: Test for the Toolbox library
copyright: Gwydion Dylan Maintainers 2000

define constant $ball-width             = 20;
define constant $ball-height            = 20;
define constant $bob-size               = 8; // Size of text
define constant $hbw                    = truncate/($ball-width, 2);
define constant $hbh                    = truncate/($ball-height, 2);
define constant $hbz                    = truncate/($bob-size, 2);

define method main (argv0 :: <byte-string>, #rest noise)

  local
    method newBall(wind-rect :: <Rect*>)
      let ball-color :: <RGBColor*> = make(<RGBColor*>);
      ball-color.red-value   := random(65535);
      ball-color.green-value := random(65535);
      ball-color.blue-value  := random(65535);
      RGBForeColor(ball-color);
      
      let new-top =
        truncate/(random(1000) * wind-rect.bottom-value, 1000);
      let new-left =
        truncate/(random(1000) * wind-rect.right-value, 1000);
      let ball-rect = make(<Rect*>,
                           top: new-top,
                           left: new-left,
                           bottom: new-top + $ball-height,
                           right: new-left + $ball-width );
      MoveTo(new-left, new-top);
      PaintOval (ball-rect);
      MoveTo(ball-rect.left-value + $hbw - $bob-size, 
             ball-rect.top-value + $hbh + $hbz - 1);
      
      InvertColor(ball-color); 
      RGBForeColor(ball-color);
      DrawString(as(<pascal-string>, "d2c"));
    end method newBall;

  let window-rect =
    make(<Rect*>, top: 100, left: 100, bottom: 350, right: 450);
  let window-title = as(<pascal-string>, "Click Mouse to Exit.");
  let my-window =
    NewWindow($NULL,            // Mac allocates storage
              window-rect,      // The bounds
              window-title,     // The title
              #t,               // Initially visible
              $noGrowDocProc, // window definition proc (WDEF)
              #f,               // No go-away box
              $NULL,            // At the back
              0);               // No refcon
  
  BringToFront(my-window);
  ShowWindow(my-window);
  SetPortWindowPort(my-window);
  TextSize($bob-size);
  
  while(~Button())
    newBall(window-rect);
    QDFlushPortBuffer(GetWindowPort(my-window), 
                      GetPortVisibleRegion(GetWindowPort(my-window),
                                           NewRgn()));
  end while;
  
  DisposeWindow(my-window);
  
end method main;