Thursday, November 29, 2007

ScriptEngine: plasma's tower of babel

today i sat down and got ScriptEngine working. this was a class that sat in libplasma for several months, but nobody had actually made sure it worked. i did that today. there were a few fixes needed in Applet and ScriptEngine, but it actually works. works very well, actually.

as a test case, and since we'd promised javascript support anyways since the beginning, i took Richard Moore's applet that hooks QtScript into Plasma::Applet and turned it into a ScriptEngine. turns out that was beyond trivial to do. btw, Richard: you rock man. *hugs* so now plasma is indeed truly javascript enabled. we probably will need to extend the bindings a bit here and there as people start pushing and prodding at the possibilities, but that's pretty trivial to do thanks to QtScript's design.

in essence what this means is that plasma can support any number of languages, all at runtime with plugins and that you can easily share your creations with others. plasma itself knows nothing about the languages themselves; in fact the whole support for this stuff outside of the ScriptEngine class (itself small at 148 lines) is about two dozen lines of code. the javascript engine itself is about 2500 lines, almost all of which are bindings; the actual plasma plugin is 313 lines long. all those numbers include both headers and source files. and yes, you can use data engines, svgs, etc from scripts (that's the whole point, after all).

the easy sharing bit comes from the platform neutral nature of scripts and that we package these puppies up into little archives: one widget, one file in any language doing anything you can dream up.

so ... ever wondered what you could do with 4 lines of javascript? wonder no more, for that picture up there is 4 lines of javascript. being beside myself with joy, i just had to make a screencast showing the script engine in action, an explanation of how it all works, proof of the system tray being well behaved these days and ending with cheesy outro music.

16 comments:

Anonymous said...

Hello,

looks like great stuff!
How many lines of code would there be if you'd done that in C++?

Anonymous said...

Usually I see the great work you do and I think "This is great!!" This time I want to thank you... Remember there is a lot of people who really appreciates your work!!

frylock said...

Awesome stuff.

Joel Calado said...

This is an awesome new world!

I gotta say, i build KDE4 svn more than 2x per day, and am using it full-time.

I'm kinda bleeding edge :P

Thanks for all the effort turning kde4 into reality!

Andre said...

Hi,
great work done there. ScriptEngine::load looks awesome :D
knewstuff comes to mind for scriptengines...

Alguém do Brasil said...

Man, this is so very cool... just want to congratulate you for your Excellent work!

Keep on going...

Anonymous said...

you rock aseigo

thanks for your hard work, kde4 is awesome... i'm using it every day full time and plasma is beautiful :)

Anonymous said...

I just wanted to say thankyou. Please don't let the trolls out there get to you. They will remain small, bitter, and quite frankly irrelevant people. While they reflect badly on the people who have (perhaps mistakenly employed them), - KDE e.V, they also reflect badly on the community.

We appreciate all that you're doing to being KDE into a new era, and the work that's going into the foundations for a truly incredible experience. We have faith in you and all the people who have the guts to work day in day out on something that can often be a thankless task. Just remember, for every moron who chooses to do nothing but criticise, there are a hundred, if not a thousand cheering you on.

More power to you! (And the Oilers! :P)

mmmm said...

It is great, but I prefer Python _much_ more ;-) I don't understand one thing - why it is bound to QtScript? I thought that Plasma should use Kross and Kross supports much more languages (Python, Ruby, JavaScript, etc).

So Plasma doesn't use Kross in the end? If it is true, that's really pitty :-( Kross seemed to me like a great whole KDE-wide unified scripting solution. If Plasma doesn't use Kross, it is sad step back in my eyes...

Chani said...

wow, you pronounced my name correctly. that's quite the accomplishment! ;)
oh, and you also managed to crash kaffeine here.
hey, kaffeine pauses if I switch desktops... I just keep finding smart litle kde things that make me happy :) and this is still just kde3. kde4 tends to have me outright gaping in amazement...

mmmm: well, if you prefer python, write the python scriptengine! duh! if it's so easy, maybe I should have a stab at it too, so that I can return to learning python.
I am confused about Kross too, though. was it not meant for what we thought it was meant for?

Aaron J. Seigo said...

@mmmm: "but I prefer Python _much_ more ;-)"

and someone else wants ruby, another group wants lua .... this is my way of not having to say no to anyone and letting the users of the software sort it out. you really don't want me making that final decision, right? ;)

so i've done the language i said i would do. now the pythonistas, rubyists, etc can do their part. it's really not that much work at all, and i'm happy to answer questions and patch any bugs that get revealed in the process.

"I don't understand one thing - why it is bound to QtScript?"

because it's light weight, fast and low overhead due to being all bundled in.

"Plasma should use Kross"

everytime i've look at Kross it has improved by leaps and bounds but it doesn't get rid of enough of the sorts of issues plasma presents to make it worth while. kross is really designed more for automating bits of apps than creating new components out of it. so, slightly different use case.

that said, since it's all plugins, anyone can prove me wrong and create a kross ScriptEngine that advertises support for all the languages =)

Aaron J. Seigo said...

@Chani: "wow, you pronounced my name correctly. that's quite the accomplishment! ;)"

huzzah, i got it right! whew!

"oh, and you also managed to crash kaffeine here."

doh! yeah, recordMyDesktop + mencoder tends to occasionally create files that kill either xine (and therefore kaffeine) or mplayer, but never both it seems. so at least one or the other works ;)

"hey, kaffeine pauses if I switch desktops... "

isn't that a cool feature? =)

Anonymous said...

hi,

i'm not a programmer, not at all, but even i realize that this "4-lines-of-code-thing" is really a great achievement.

Chani said...

not only did you get it right, you got it *exactly* right. it matched so well with how I say my name that I was thrown off for a second - most people in north america can't quite get the 'a' sound right. it always seems a little tiny bit off.

btw, the file worked fine once I downloaded it and played it locally. I think it was something about the streaming that tripped it up.

Javier said...

I love this screencast's outro music!
It's amazing how the script engines work. You guys are geniuses.

Anonymous said...

It's unusual for a programmer, someone used to being very precise, to flagrantly ignore common punctuation. If you tried that when writing code, most compilers would balk at you.

It's very distracting and makes you look bad.