Re: Calling script libraries
Re: Calling script libraries
- Subject: Re: Calling script libraries
- From: has <email@hidden>
- Date: Fri, 19 Apr 2002 00:53:35 +0100
Malcolm Fitzgerald wrote:
>
To some extent this is a RTFM question but I'd like to get some
>
opinions.
To be honest, I don't think the manual for this has ever really be written.
You just devise your own as you go.
>
What's the best way of calling these library's into the work-space of
>
another library?
Oh, I'd definitely use the 'import' statement.
Huh? What? No import statement?? Whaddaya mean?!? <grumble-grumble>
Hmph... Well okay, here's hoping for good news from the WWDC in three
weeks' time. In the interim, I've been using a lot of dynamic loading
because a lot of my stuff is still in-development, and static loading is a
pain when you need to make frequent updates.
At the moment, I'll load everything into the base script:
--------------
property someLib : missing value
property anotherLib : missing value
on loadLibs(pathToLibFolder)
set someLib to load script file (pathToLibFolder & "someLib")
set anotherLib to load script file (pathToLibFolder & "anotherLib")
end loadLibs
on run
--get path to library folder somehow
loadLibs(result)
main code
end run
--------------
Now, let's say that someLib has to access anotherLib's handlers. I used to
do this by putting a 'global anotherLib' declaration in someLib, but I've
kinda gone off this approach for one reason or another. Instead, I now put
an init() handler into someLib, like so:
--------------
--******* someLib *******
--init
property anotherLib : missing value
on init(libStore)
set anotherLib to libStore's anotherLib
end init
--main handlers
on foo()
return "foo " & anotherLib's bar()
end foo
--------------
The libStore argument should be a record/script object containing the
loaded libraries.
All I gotta do now is extend my main script's loadLibs() handler, like so:
--------------
on loadLibs(pathToLibFolder)
set someLib to load script file (pathToLibFolder & "someLib")
set anotherLib to load script file (pathToLibFolder & "anotherLib")
--
tell someLib to init(me)
end loadLibs
--------------
This passes the entire script object into the someLib module's init()
handler, which deals with someLib's own properties as appropriate.
A cruder approach would involve someLib loading anotherLib directly from
disk, but this is less efficient as you may end up with multiple instances
of the same library loaded here, there, everywhere. Not such a good idea,
however: even in these days of terabyte office suite installations, nobody
really likes a RAM/disk hog.
So as far as libraries that need other libraries goes, the above is the
best solution I've come up with to date. If you check out AWPS or tableLib
on my site, you can see this sort of stuff in action. [Note: I've recently
changed the AWPS demos. They used to load the libraries at every run, but
now they prompt for them at the first run and retain them internally
thereafter. There's no auto-update mechanism at the moment, however - if
you update AWPS you'll have to open and recompile the demo applets to get
them to load the new version.]
From there onward, it's really down to your best needs whether you want to
load everything once (e.g. at first run), or every time your applet/script
is run. Or even, as Jon as suggested, have a self-updating hybrid that's
basically static, except when it's being dynamic.
HTH
has
(WWSND?;)
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.