On 16 Jan 2016, at 23:39, has <email@hidden> wrote:
Shane Stanley wrote: > > On 16 Jan 2016, at 20:30, has <email@hidden> wrote: >> >> Does ASOC support return-by-argument, e.g. for getting NSError**? > > set {theResult, theError} to (theFileManager's copyItemAtURL:theSourceURL toURL:theDestURL |error|:(reference))
Thanks. Kinda wonky design though; wonder why ASOC doesn't just take an actual reference? What if it's an inout parameter - how do you pass a value in?
Someone once suggested it was based on what happened in another bridge; I don't know if that's true or not. I'm not sure about inout -- I can't say I've struck any cases where I've needed to do it. In XCode apps, you can use "contents of" when overriding methods that take pointers to pointers:
on dataOfType:typeName |error|:outError set contents of outError to current application's NSError's ...
The other downside is it doesn't work for methods that don't return a result. There aren't many, and most have workarounds, but there are exceptions.
As for this particular use case, -[NSTask isRunning] is deprecated, so that's not an option.
Deprecated methods are the only ASObjC option for several block-based methods. > Running NSTask in ASObjC is about on-par with do shell script time-wise.
Yeah, I'm not bothered about that: everything in AppleScript [except AE dispatch] is dog-slow compared to other languages (e.g. Python's sort routine is 100x faster than mine, and stable to boot, so merely being "as fast as" is actually a pretty good deal).
I think it's an *excellent* result, considering. Speed-wise ASObjC generally only starts to lag when there's a lot going on, like large repeat loops. That's when it's time to look at wrapping a framework. BridgePlus's -colsToRows: is a good example -- pass repetitive stuff to Objective-C where possible.
The purpose of creating these libraries is to provide greater capability, robustness, and ease of use.
That's one of the reasons I have a problem with your approach: you're trying to serve three masters. The benefits of NSTask over `do shell script` are that it allows you to interact with a Unix-style process directly, piping data in and out, and to operate asynchronously as well as synchronously. (TBH, the TaskLib's kind of borderline - I'll ditch it if I decide it doesn't add sufficient value over what currently exists, but it'd be nice to get a decent prototype working first so I can properly judge it.)
Well you don't have to use a terminationHandler. But if you need to, why not put it in a framework? >> (I need a way to do stuff like call OSADisplay to get the source-code representation of any AS value.)
I was playing with this recently. Here's a lib:
use framework "Foundation"
script BaseObject -- the parent script object, required for AppleScriptObjC inheritance end script
on makeThingWith:aList -- call this to make a new smartList script property parent : BaseObject -- for inheritance property theStore : missing value -- where the value is stored
on asList() return theStore as list end asList
end script set myThing to result set theStore of myThing to current application's NSArray's arrayWithArray:aList -- set initial value return myThing
end makeThingWith:
And this calls it:
use theLib : script "TestLib" set x to theLib's makeThingWith:{4, 6, 1, 2, 3, 7, 1, 4, 3, 3, 7} x's asList()
Run it in Script Editor. Now delete the last line and run it again. You get error -1763, which is errOSACantStorePointers. So presuming that SE is using OSAScript's -richTextFromDescriptor:, I assume it's calling OSAStore somewhere. (Radar #24026920 if anyone is reading.)
My app had the same issue. I tried OSADisplay and OSACopyDisplayString, and in the end chose the latter with kOSAModeDisplayForHumans to get just «script» if OSAStore throws errOSACantStorePointers (which I had to check anyway). I *think* OSACopyDisplayString would give the full source, but it was little use to me because it still contains raw ocids. Anyway, one of OSADisplay or OSACopyDisplayString triggered errOSACantStorePointers, and one didn't. (Oh for a better memory...)
And ideally I want something that isn't going to complain when a «class ocid» specifier is passed to it.
You need to be *very* careful with specifiers containing ocids. If you're running under 10.10, you'll crash just trying to get a representation (maybe not immediately, but soon). I duplicate them and replace the relevant descriptors with descriptors containing string descriptions first, which is fairly laborious. I also walk through all descriptors' records and lists, getting the source of each and building my own final string. There's a fair bit happening there...
(I use OSAScript's private -compiledScriptID method to get OSAIDs. I should log a bug requesting it be made public...) Yeah, I'm aware ASOC Explorer has very nice output logging. (And yeah, it'd be nice if the AS team would just nab it off you - Jon's Commands-style - and merge its capabilities into SE.) But this is for the libraries I'm doing, so they need to be free, portable, and self-contained. And preferably hackery-free (if indeed this is even possible in AppleScript).
Like I said, good luck with that. |