2008 10 08JSCocoa, a bridge from Javascript to Cocoa
JSCocoa ...
- allows you to write Cocoa programs in Javascript (via JavascriptCore, WebKit's Javascript engine)
- works on x86 and PPC and requires Leopard (an uptodate Leopard, 10.5.2 from back then crashes)
- is open source !
Syntax
- Only dots ! Everyone loves dots !
NSWorkspace.sharedWorkspace.activeApplication.NSApplicationName
- An
instance
command to replacealloc.init(…)
NSButton.instance({ withFrame:NSMakeRect(0, 0, 100, 40) })
- More dots ! Did you know that a message like
setTitle:
is really a dot trapped in a closet, begging to come out ?// Changes window title window.title = 'Hello !'
- A split call syntax, to almost have ObjC-like calls — if you use jQuery you'll feel right at home
this.perform({ selector:'printSomeDots:', withObject:null, afterDelay:0 })
- Some JS-like manipulation of arrays and dicts :
myNSMutableDictionary.mykey = 'value' myNSMutableArray[5] = 'hello world !'
But Javascript arrays and hashes are not (yet) converted to NSArray and NSDictionary.
Meaningobject.wantsADictionary({fontSize:14})
will fail.
And of course the Javascript benefit of ending your lines without semicolon barbwire.
Samples
There's only one :) — A Core Animation process viewer.
Get it
- Download it from its homepage JSCocoa home
- Or from its source home Google source page for JSCocoa
Patrick Geiller
2008 10 09
(English below ! :) )
Oui, c'est possible. Pour l'instant, tout est ouvert et l'interpreteur passe par 2 endroits pour appeler des fonctions C ou Cocoa :
OSXObject_getPropertyCallback
recupere les fonctions C classes ObjC, constantes : filtrepropertyName
pour interdire des fonctions C ou classes ObjC (interdire tout acces a NSView par ex)jsCocoaObject_getProperty
recupere les propriétés des instances : le nom d'un method, d'un propriété : filtrepropertyName
et inspectecallee
pour interdire l'acces a des methodes ou propriétés d'une instance.
// English !
Right now everything is open : anyone can call anything : any C function, class method, …
- To restrict access to only certain classes, C functions, structs, constants : filter
propertyName
inOSXObject_getPropertyCallback
- To restrict access to only certain methods of certain classes, (eg allowing to call anything but
alloc
andinit
inNSView
) filterpropertyName
with the help ofcallee
(the instance being called) inOSXObject_getPropertyCallback
Tom Robinson
2008 10 10
Here's a command line wrapper I threw together: http://tlrobinson.net/blog/?p=55
Ce projet à l'air vraiment prometteur, je vais le suivre avec attention. :) Est-ce que c'est possible d'isoler l'interpreteur de script afin d'éviter que les scripts puissent atteindre toute l'application hôte ? (Pour faire un système de plugins JavaScript, par exemple).