Scope of globals, parents and children, "load script" and all that jazz
Scope of globals, parents and children, "load script" and all that jazz
- Subject: Scope of globals, parents and children, "load script" and all that jazz
- From: Sander Tekelenburg <email@hidden>
- Date: Thu, 17 May 2001 05:21:06 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm trying to reorganize a rather large script (1000+ lines and growing) by
separating it into a main script (parent) and moving all handlers into a
separate script library (child) that is called by the main script with the
"load script" command.
However, I ran into something that tells me I seem to have problems
understanding the scope/meaning of globals. The original ('all-in-one')
script uses a lot of globals (17). To my surprise, I found that in order to
get everything to work, I needed to do 2 things in the script library :
1) declare those same globals again, at the top of the script
2) declare them yet again within each handler! (well, only those globals that
apply to that particluar handler)
The second seems to be needed to have the values of the globals available in
the child's handlers. The first seems to be needed to get the values returned
by the handlers available again in the parent script.
The script does seem to work fine this way, but I had expected to need
neither of these 2 steps. I thought the loaded script would 'see' the
Parent's globals and that therefore all that would be needed for this
transistion was to just cut&paste the original script's handlers into a new
script and have the main script load the child with the "load script"
command. But apparently both the parent and the child must be 'manually'
informed of each other's globals. Why? And is there a more elegant way to do
this?
I've looked through the chapters in the AppleScript Language Guide that seem
relevant, but it isn't getting any clearer for me.
Insight much appreciated! :)
(In the long run I will probably split the library up into several libraries.
And I would like to get rid of as many globals as I can. But for now I was
just trying if I could easily switch to this construction without having to
get rid of all globals just yet.)
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOwNDnesywKfXgqKdEQIzPACfUYhuKqHZzX29jRAZRTg68I85eB8AoNa+
e8+CoGk8iLogG0DtnuKeVlLf
=BTed
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"