Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!usc!apple!bc From: bc@Apple.COM (bill coderre) Newsgroups: comp.sys.mac.hypercard Subject: Re: About globals in XCMDs Message-ID: <43628@apple.Apple.COM> Date: 4 Aug 90 00:19:49 GMT References: <1425taylorj@yvax.byu.edu> Organization: Apple Computer Inc, Cupertino, CA Lines: 40 In article <1425taylorj@yvax.byu.edu> taylorj@yvax.byu.edu writes: |As far as I know, no language directly supports the second kind: persistent |globals. But there are lots of ways to do it yourself. Here are a few... A good mechanism for variables which are persistent across XCMD calls but not across program runs can be gleaned from how many device drivers are written. Basically, you need 3 or 5 calls (the optional ones are in parens): fooINIT -- takes no argument, returns a handle (fooWARMUP) -- "gets ready" to do work fooGO -- does some quantum of work (fooWRAPUP) -- stop doing work fooDIE -- go away now INIT should create a handle, stuff whatever constants or whatnot in it, and return it. The Hypercard program is responsible for keeping the handle around, and sending it with EACH of the calls below. WARMUP should do whatever is needed to prepare to do work without actually doing it. In a printer driver, this would be to allocate the port, send setup codes, etc. On a screen saver, this would be to turn the screen black and set up an interrupt routine to check for events. GO does a small amount of work, such as printing a little text or drawing a few stars on the black screen. WRAPUP takes care of shutting the job down, such as padding and flushing the buffe and closing the port, or sending a message to the window system to update itself. DIE destroys the handle. If the HC program doesn't call die, it is a fatal error. Obviously, many XCMDs won't need WARMUP and WRAPUP. And there might be different GO commands, to do different things. But the basic ideas of INIT creating a handle before doing any work and DIE deleting it on program exit are the important ones to allow for persistence in many systems.