CoffeeScript in qml, proof of concept.
In case anyone's interested, I hacked together a fork of qtdeclarative (based on dev) that allows coffeescript to be used in QML:
I've just been using it in a small hobby project, so I'm not making any promises about how well it works.
You can make a standalone script file with a .coffee extension, and add:
@.pragma language "coffeescript"@
@import "test.coffee" as Test@
In qml, for property assignments and signal handlers, instead of using a colon, you can put a ->
source -> if someFlag then "a.qml" else "b.qml"
if event.key is Qt.Key_F1
event.accepted = true
Something to be aware of is that coffeescript will not let you assign a qml global (e.g. property on current object) with "property = value", and will instead declare a local 'var property'. To work around this you'll need to assign an id to the object and use "id.property = value".
Things I've been thinking about for future work:
- hooks for qml/js translation in qtdeclarative, and coffeescript support in a plugin
- writing of translated qml/js (e.g. for build time translation)
- a pure coffeescript dialect of qml, using coffeescript's object notation
- modified coffeescript compiler that understands qml globals
- sourcemap support for debugging
Hm, that's an interesting development! Not that it makes much difference to me personally, I would really like to see proper language, like Python, instead of JS :)