mod servers (Was: Re: hash arrays and other mysteries)
mod servers (Was: Re: hash arrays and other mysteries)
- Subject: mod servers (Was: Re: hash arrays and other mysteries)
- From: has <email@hidden>
- Date: Sun, 21 Oct 2001 02:42:43 +0100
Trying to work out the best way to implement The Super-Deluxe ModServer Of
My Dreams (complete with chrome trim and furry dice), I've poked around
some and figure I could do either of the following:
1. A script server that can be used to load up the handlers from one,
several or all of the mod files in a specified folder by placing the
following in the top of your scripts:
property modsList: [a list of filenames] --e.g. {"readIn", "qSort",
"AssociativeLib"}
property parent : import(modsList) of application "ModServer"
The script would get the contents of all specified files, concatenate them
(coerce each to text, join the strings into one and pass through 'run
script' to get a single script), and return the script object.
I could also add the ability to specify mod sets via text file containing a
list of filenames that can be specified instead of individual handlers, and
an "AllModsInOne" property in the server that contains every handler if you
just want them all at once (faster than recompiling specified handlers each
time).
Is this a good approach? Any potential problems in there that I'm missing?
Or, how about:
2. A script server that writes all the handlers directly into an empty
applet, quits the old one and replaces it with the new. A little less neat
on the server side (as well as the server, it requires a second 'empty' to
be trailed round after it), although it would allow you to use the more
familiar:
property parent : application "ModServer"
to load all the server's handlers.
Odd note: I did try storing new scripts over existing ones, but strangely
the new handlers didn't seem to become available when I did this, short of
opening the server in Script Editor and recompiling and resaving it there.
Can anyone confirm this is what happens or tell me if I was just doing
something wrong?
Am I right in thinking that the script object, once stored in the parent
property, will remain there until/unless you recompile your script again?
If yes, is there any way to force it to reload every time the script loads?
Perhaps not surprisingly, "set parent to..." doesn't seem to cut much ice.
Presumably you can always store them under a regular name if you want to do
something like:
global readIn, qSort
set readIn to readIn of application "ModServer"
set qSort to qSort of application "ModServer"
...
readIn()
or:
global allHandlers
set Mod to allHandlers of application "ModServer"
...
Mod's readIn()
Either of which would ensure your handlers reloaded every time your script
executed - although would there be any advantage in this? (Perhaps it's
better to leave the originally loaded mod in your script; if an improved
version comes along later then you'll have to recompile your scripts in
order to use them.) What would be best practice?
Your thoughts and comments much appreciated. (I'm skating at the edge of
what could loosely be called 'competency' here... it took a while just to
figure this object stuff out, never mind how to use it...)
has
p.s. Sorry if I'm going on a bit...