Re: Inheritance and Loaded Libraries
Re: Inheritance and Loaded Libraries
- Subject: Re: Inheritance and Loaded Libraries
- From: has <email@hidden>
- Date: Sun, 31 Oct 2004 21:17:51 +0000
Axel Luttgens wrote:
Paul also noticed that the parent declaration isn't needed in the
main script for the "tell my XLib to runTest()" to work:
Hmph. Missed that... must be slipping... old age, y'know.
Still, that more or less answers my previous comment - "If there's an
interesting question here, it's why 'tell my XLib to runTest()'
should have worked?"
This works because of AppleScript's scoping rules.
Not definite; but I'd certainly strongly suspect the resolution
process for global variables being the culprit. (Reason #87 why I
prefer Python over AppleScript: Python's variable scoping rules were
never dropped on their head as a baby. Python's 'globals' are
module-level, which is as far as any sensible namespace-savvy
language should go.) I don't see anything about this in the ASLG so
I'd guess it's undefined behaviour, something that's best avoided -
the bugs found by the OP and myself tend to back this up.
(e.g. Assigning handler objects to variables is another example of
undefined behaviour, and similarly buggy.)
I suppose the above illustrates what has meant by writing:
"Nothing to do with inheritance or loaded libraries; you just need
to send the 'get' event at the right place. You're dealing with plain
old AppleScript here, not the Apple Event Object Model[...]".
No, I was referring to the OP's original code, which once you get rid
of the irrelevant [and somewhat gratuitous] parent property looks
like:
runTest() of XLib of application "ScriptRunner"
Point is you can't send AppleScript references via Apple events; they
don't support it. Only things you can do with AppleScript applets is
call their top-level handlers and get and set their top-level
properties, so there's three ways you can call runTest that don't
rely on dodgy, undocumented methods:
1. Send the applet a 'get [property] XLib' Apple event. (Not to be
confused with using 'get' to evaluate an expression, despite
AppleScript using the same keyword for both.) This returns a copy of
the 'XLib' script object whose runTest handler can then be called
locally. This is what I was referring to above.
2. Send the applet a copy of your entire script. Have the applet call
a handler in that script, passing a copy of itself as parameter,
allowing the handler to call the runTest handler in the applet
script's XLib property. This is what I suggested the OP use instead,
and is similar to the way ASS works.
3. Add a top-level handler to the applet that calls XLib's runTest
handler for you:
on runTest()
XLib's runTest()
end runTest
You can then call that handler using a conventional:
tell application "ScriptRunner" to runTest()
They're not fully interchangeable, so use whichever one best fits
your particular requirements.
Regards,
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden