[Qtscript-bindings] Closure API
Peter Kuemmel
syntheticpp at gmx.net
Mon Jan 19 15:36:52 CET 2009
Thanks Kent,
that's what I'm looking for.
I searched the docs for "closure" but found nothing.
Closure is a common name for this mechanism:
http://en.wikipedia.org/wiki/Closure_(computer_science)
I would rename the section title to something like
"Closures: Nested Functions and the Scope Chain"
Peter
-------- Original-Nachricht --------
> Datum: Mon, 12 Jan 2009 11:12:33 +0100
> Von: Kent Hansen <khansen at trolltech.com>
> An: qtscript-bindings at kde.org
> Betreff: Re: [Qtscript-bindings] Closure API
> Hi Peter,
> Maybe you can use the approach shown here:
> http://doc.trolltech.com/4.4/qtscript.html#nested-functions-and-the-scope-chain
> QScriptValue::scope() and QScriptValue::setScope() are mistakenly
> flagged as internal at the moment, but this should be fixed for 4.5.
> By passing the QScriptValue::ResolveScope flag to
> QScriptValue::property(), the scope will be looked up (recursively), so
> that's how you implement nested closures to any depth.
>
> Regards,
> Kent
>
>
> Peter Kümmel wrote:
> > 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
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Qtscript-bindings mailing list
> > Qtscript-bindings at kde.org
> > https://mail.kde.org/mailman/listinfo/qtscript-bindings
>
> _______________________________________________
> Qtscript-bindings mailing list
> Qtscript-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/qtscript-bindings
--
Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
More information about the Qtscript-bindings
mailing list