Enumerations?

34 views
Skip to first unread message

Gus Mueller

unread,
Oct 8, 2009, 6:56:28 PM10/8/09
to jstal...@googlegroups.com
So I'm working a bit on AppleScript support to Acorn, and making sure
everything is up to par w/JSTalk in the same areas, and I'm finding
that JSTalk is missing something pretty obvious- enumerations.

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/

Jonathan 'Wolf' Rentzsch

unread,
Oct 9, 2009, 3:07:11 AM10/9/09
to jstal...@googlegroups.com
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?
- jwr

Patrick Geiller

unread,
Oct 9, 2009, 4:56:35 AM10/9/09
to jstal...@googlegroups.com
> 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.


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

Gus Mueller

unread,
Oct 9, 2009, 1:07:46 PM10/9/09
to jstal...@googlegroups.com
On Oct 9, 2009, at 12:07 AM, Jonathan 'Wolf' Rentzsch wrote:

> 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.

Gus Mueller

unread,
Oct 9, 2009, 1:09:48 PM10/9/09
to jstal...@googlegroups.com
On Oct 9, 2009, at 1:56 AM, Patrick Geiller wrote:

> 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.

Reply all
Reply to author
Forward
0 new messages