Re: AS Library Question
Re: AS Library Question
- Subject: Re: AS Library Question
- From: Shane Stanley <email@hidden>
- Date: Thu, 17 Dec 2015 12:30:33 +1100
On 17 Dec 2015, at 7:56 AM, Stan Cleveland <email@hidden> wrote:
>
> This may have been an off-handed remark on your part, has, but is an attractive and tenable option.
Just be aware that there's another issue when ASObjC code is involved that affects both libraries and code loaded with load script, and from a trouble-shooting perspective, it's probably a *little* easier to deal with -- and spot -- using libraries loaded with a "use" statement.
The problem is one of namespace, and particularly the fact that AppleScript's namespace is case-insensitive, whereas Objective-C's is not. There is at least one nasty edge case.
So if you have a variable Foo and a variable foo, when you compile they all end up using whichever version the compiler sees first. At run-time, it generally doesn't matter if your lib uses foo and your calling script uses Foo -- except if foo is the name of an ASObjC method. (The issue only happens with methods that take no arguments, and you can avoid it with method names that contain mixed case by piping them in your lib, so it's really only an issue for all-lowercase parameter-less method names.)
Anyway, the issue can bite you however you load the library. The only difference is that, if your script is loaded via a use statement, because the lib is then seen first, its version is used, so the ASObjC code will run fine, and the fact that your calling script's Foo has changed to foo won't matter. And seeing the change in your editor is obviously more helpful; debugging issues in libraries/loaded scripts is always more difficult.
In the context of scripts sharing the same component instance, like those run from app script menus and panels, there's obviously a greater risk, because the namespace is also component-based, so the name identifier might be defined by some other script entirely. Basically, if you're going to use ASObjC-based libraries in such cases, you need to be more careful with your naming of things.
In practice, I only hit my first case of it very recently. I've probably been more immune because I tend to use camelCase names (names using underscores should also be fine, as long as they don't include trailing underscores).
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden