Replacement of QTScript continues

Pedro de Carvalho Gomes pedrogomes81 at gmail.com
Tue Jun 9 16:56:13 BST 2020


Hi all,

I finally concluded the first version of the scripting engine porting
to QJSEngine. It now has a functional console, and it runs
successfully the "Cool Stream" script ( at radio_station_service
folder). I took the chance to remove some services from the playlist
that are no longer available.

Still there's some way ahead. The most important task is to define a
replacement for QTScript Bindings (imported with
"Importer.loadQtBinding"). These were how QT classes were exported to
scripts. Many old scripts make use of these, and would complain if
there's no equivalent functionality. For now I think the best solution
is to write our own "Importer.loadQtBinding" and expose the most
common QT classes. But probably this approach should be desincouraged
in favor of a QML-based approach. Still for the purpose of the next
release this should work.

For the brave ones, the changes are here:
https://invent.kde.org/multimedia/amarok/-/commits/replace_Qtscript_with_QtQml

Cheers,

Pedro

On Fri, Jun 5, 2020 at 10:20 PM Pedro de Carvalho Gomes
<pedrogomes81 at gmail.com> wrote:
>
> Hi all,
>
> I write to update about my work on replacing QTScript with QJSEngine.
> I have just pushed to the branch a substantial change, which includes:
> - fully functional Script console with JS console logging
> - loading of old scripts (though with errors, depending on what's used)
>
> If you have the interest, take a look at the working branch:
> https://invent.kde.org/multimedia/amarok/-/tree/replace_Qtscript_with_QtQml
>
> There's still quite some work ahead. At least if the goal is to
> minimize changes to older scripts. The main issue is that the
> QJSEngine API provides *way less* features than QScriptEngine. Also,
> the documentation is not so complete.
>
> One example: QScriptEngine had "newFunction" which allowed any
> method/function to be exposed to the script engine. There's no such at
> QJSEngine, but I managed to implement an equivalent solution by
> 1) creating a QObject with a Q_INVOKE method,
> 2) exporting the object: QJSValue scriptObj = engine->newQObject( myQObj );
> 3) get a reference to the method: QJSValue scriptFunction =
> scriptObj.property("methodName");
> 4) create a global property to the method:
> engine->globalObject().setProperty("functionName", scriptFunction);
>
> The main issue I have now is that QJSEngine does not have an
> equivalent to QScriptContext. This provides invocation information
> that is necessary; especially a reference to the "this" JS object.
> Without it I can't think of a solution that avoids rework at all
> current scripts.
>
> Another issue is that there's no direct equivalent to QtBindings.
> These is specifically useful to manipulate QT widgets via script.
> However those should naturally be replaced with some QML equivant,
> though I couldn't look at it yet.
>
> If there are more people interested, I'd be really glad to help bring
> on board. There's a lot of fun stuff to work with.
>
> Cheers,
>
> Pedro


More information about the Amarok-devel mailing list