Re: library of subroutines - help needed
Re: library of subroutines - help needed
- Subject: Re: library of subroutines - help needed
- From: Ken Victor <email@hidden>
- Date: Sun, 17 Dec 2000 11:12:50 -0800
i would really, really like to be able to use compile scripts in
separate files. if i try to put the following statement in a script
that is to be loaded:
property parent : main
where main is the name of the script in my main "program", it doesn't
compile complaining that "main" is undefined.
so... is it possible to have libraries (plugins) of compiled scripts
in separate files that can access the handlers in the script in the
calling file?
thanx,
ken
At 12:49 AM -0800 12/17/00, Ted Wood wrote:
i would like to have a compiled script that uses various "plug in"
scripts in separate compiled script files. in the main script i would
like to have a number of utility routines that could be used by each
of the plugins. i can successfully load and execute the plugins;
however, i haven't been able to figure out the proper syntax in order
to be able to use routines in the main script from the plugins.
my main script is something like:
on run()
...
DoDelete()
...
end run
on DoDelete()
set DeleteScript to (load script file DeleteScriptName)
tell DeleteScript to DoIt()
end DoDelete
on LogMessage( theMessage)
...
end LogMessage
and then the delete plug in might be:
on DoIt()
...
LogMessage("from Delete PlugIn")
...
end DoIt
its the call to LogMessage in the plugin that doesn't seem to work.
i've also tried using:
tell parent to LogMessage("from Delete PlugIn")
and this doesn't work either
is this kind of structure possible? (it seems like it should somehow
be possible.) and if so, how do i get it to work?
thanx,
ken
Hi Ken,
I don't know how much help I can provide, but I've learned a few
things about Parent and Child scripts. In my first attempts at
loading script object, I was loading from external files, as you
are, but now I'm learning to use script objects within the main
script. To the script executing, the resulting script object is the
same, whether you load from an external file, or call a local script
object. (ramble... ramble.... ramble....)
I believe you need to explicitely inherit the parent's handlers and
properties using:
property parent : <name of parent script object>
EXAMPLE: (copied from page 334 of the AppleScript Language Guide)
script X
on sayHello()
return "Hello, " & getName()
end sayHello
on getName()
return "Emily"
end getName
end script
script Y
property parent : X
on getName()
return "Andrew"
end getName
end script
tell Y to sayHello()
-- RESULT: "Hello, Andrew"
What happens here is script Y is inheriting script X's handlers, but
since script Y already has a getName handler, it uses that one
during that execution, resulting in "Hello, Andrew".
Hope this helps a bit.
Ted.