[Kde-perl] Re: perlQt question

Germain Garand germain at ebooksfrance.org
Fri Aug 29 00:29:35 CEST 2003


Le Jeudi 28 Août 2003 07:48, Richard Dale a écrit :
> On Wednesday 27 August 2003 23:37, Germain Garand wrote:
> The power of the new PerlQt synchronicity based bug prediction system! We
> can already be working on the problem 48 hours before a PerlQt user finds
> it.
>

Yes! It's still experimental technology, but very promising! :-)

> I'm having problems getting operator overloading working in QtRuby, I don't
> know how you've solved it for PerlQt. Is there a way to distinguish between
> static methods and instance methods in the SMOKE runtime?

you can do it by testing the returned methods after a search
e.g with meth.flags & Smoke::mf_static, 
but for the Smoke runtime, it's up to you to give a "this" object or not
(cf. the second argument of xcall_Q* functions)
So it's rather up to the binding to make the distinction.

In Perl one uses the "overload" Core package to overload selectively the 
operators in a package, and redirect those calls to a handler.

So the best solution I found to this problem is: from this operator handler, 
we first 'eval' a  method call in the current class, then a static one in 
GlobalSpace... If both fail, we die like this:

2 + $qpoint

--- No method to call for :
        QPoint::operator-(2)
Closer candidates are :
        QPoint& QPoint::operator-=(const QPoint&)

at test line 32.
--- No method to call for :
        QGlobalSpace::-(QPoint, '2')
No close candidate found.

> the QtRuby runtime first looks for a method of
> the form -a(b), which should be missing in this case, and then it should
> look for -(a, b) as a static method in QGlobalSpace.
>
> However, it finds the unary static operator in QGlobalSpace looking for
> -a(b) and assumes it's an instance method, and calls that, so it wrongly
> evaluates the expression as a, (-b)
>

mmh... I see... We aren't affected because we don't look in GlobalSpace
 from AUTOLOAD, only from the handler's second try.

err.. I'd even say our unary minus operator handler cannot
have *any* bug at the moment
<rushes to add it>
:-} 

> p1 = Qt::Point.new(5,5)   => (5, 5)
> p2 = Qt::Point.new(20,20) => (20, 20)
> p1 - p2                   => (-20, -20)
>
>  findMethod() in Qt.xs doesn't distinguish between static and instance
> methods - does it need to - is that the way to solve this problem?
>

it could easily with the afore mentionned test,
but we can't use that because the PerlQt syntax allows static/instance methods 
to be called the same way.

e.g saying foo() in a Qt-derived package equates to either Package::foo() or 
this->foo()

but you are right, now that I think about it, there are cases where we are 
sure we are looking for a static... so this could avoid some errors/abuse.



More information about the Kde-perl mailing list