[Qtscript-bindings] Closure API

Peter Kümmel syntheticpp at gmx.net
Sun Jan 11 15:39:49 CET 2009


The current QtScript API only supports one
closure QScriptValue per function.
The attached file proposes an extensions to
the API to support multiple closure values.


In short:

With the help of QScriptValue::setData()/data()
it is possible to implement a closure on the
C side, for instance see 1. in closure.cpp which
implements this closure:

newCountDown = function(start) {
                  var counter = start;
                  var countDown = function() {
                                    counter--;
                                    return counter;
                                  };
                   return countDown;
                 };


But if you wanna use multiple closure values
it is necessary to:
1. make them fit into one QScriptValue, or
2. to make them properties.

1. has the disadvantage that it complicates things and
2. makes the closure data accessible from JS which
definitely contradicts the idea of closures.
Therefore the wish to extend the current QtScript API.

Or is there other way to handle multiple closures which
I have overseen?

Peter
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: closure.cpp
Url: http://mail.kde.org/pipermail/qtscript-bindings/attachments/20090111/8bd379a8/attachment.bat 


More information about the Qtscript-bindings mailing list