Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parent property by "path to", passing variables between script files



Matt Neuburg wrote:

> >A 'load script' command will read a script file and create a new script object
>from that data. e.g. If you call it twice, you'll get two initially identical
>objects, not one, so changes made to one will not affect the other. The solution
>is to load each script only once, and share them throughout your entire program.
>
>Surely the solution is to call store script, so that changes are written out
>to disk...? m.

Not when you're dealing with libraries; that'd just be a lot of unnecessary make-work. All you want is a single library object in-memory which the rest of your program can get access to as necessary; the library and its state is then shared for real, automatically and cost-free. The problem is, what to do when that library object is loaded into one namespace and you need it in another, separate one? (Admittedly, you can 'cheat', but that's just storing up other kinds of trouble for later on.)

Other languages provide built-in 'import' mechanisms that handle all the relevant grunt-work for you: the first time the interpreter encounters an 'import FooLib' statement it loads FooLib from disk and also stores a reference to it in an internal cache; on subsequent 'import FooLib' statements it just fetches the existing FooLib object from the cache, so the entire program ends up sharing the same FooLib object.

AppleScript doesn't provide a native 'import' option, so to get the same result you either have to roll your own (typically ad-hoc) solution or use a third-party importing system like Loader. Takes a bit more code to achieve, though I think the bigger problem is the lack of information on how to do it: not just 'What is a library?' and 'How do I use it?', but also how - and why(!) - to design and build an application this way, what's good practice (and what's not) and what existing materiel is out there to help you on your way. Loader's probably the closest thing to a 'standard' solution there is, and you can see how much coverage it gets. :p (Plus a certain lazy SOB never has gotten to finishing the developer docs yet, which doesn't exactly help.:)

has
-- 
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.