Here's a list of things that automatically pop into my head when
thinking of this:
What about namespaces? I'm not sure having enums just sit in the
global context is a great idea.
Oh, what about giving the app an opportunity to execute some simple
code when the script is run? Call a method called - (NSString*)
JSTalkScriptBlah; (need to think of another name) which returns a
little JS snippet, which would be executed on the context? That way
Acorn could return a script like:
Acorn = new Object();
Acorn.TOP_LEFT = 0;
Acorn.TOP_RIGHT = 1;
...
Maybe call an optional method on the root object "JSTalkEnumerations"
which returns a dictionary, which we then set on a global object,
similar to above- only done in objc land.
Other ideas?
-gus
--
August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
If you want enum names, you can get them by building a bridgesupport
file with gen_bridge_metadata. They look like this :
/System/Library/Frameworks/AppKit.framework/Versions/C/Resources/
BridgeSupport/AppKit.bridgesupport
<enum name='NSAWTEventType' value='16'/>
<enum name='NSAboveBottom' value='4'/>
<enum name='NSAboveTop' value='1'/>
<enum name='NSAddTraitFontAction' value='2'/>
<enum name='NSAdobeCNS1CharacterCollection' value='1'/>
Feed this file to BridgeSupportController and enums will be available
in the global scope, on-demand. One downside is that bridgesupport
files don't have groups, eg there is no enum group for all possible
NSString encodings. Bridgesupport enums are just a big flat list.
-Patrick
> Does Javascript/JSTalk really need AppleScript-enumerations. JS is
> rather dynamic-symbol happy as-is, so I don't see what enumerations
> will really buy you. Have any examples?
Yea- so in Acorn you can use AS to crop an image, with an optional
anchor param, which takes one of 9 values- "top left" top middle",
etc. The AS looks like this:
resize canvas width 100 height 100 anchor position middle left
The current way to do it in JSTalk (from what I've currently got
written anyway) is:
doc.setCanvasSize_usingAnchor(NSMakeSize(100, 100), "top left");
I'd rather not have the strings in there. I'd rather it be something
like:
doc.setCanvasSize_usingAnchor(NSMakeSize(100, 100),
Acorn.anchor_top_left);
Or something else along those lines. This way the scripter can't
misspell it. I suppose I could just throw an error if I don't
understand the string, but I don't like that approach as much.
> If you want enum names, you can get them by building a bridgesupport
> file with gen_bridge_metadata. They look like this :
Yea- that's a good idea too. The JSTalk editor would have to look in
the bundle and load those up for the app it's calling, which wouldn't
be too hard to do.