Reflect.compareMethods

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Reflect.compareMethods

Jan_Flanders
Hi,

I'm a bit puzzled about the Reflect.compareMethods function. (I'm testing on the neko platform.)

The documentation on the haxe site says: http://haxe.org/api/reflect

static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
Compare two methods closures. Returns true if it's the same method of the same instance.

It seems to work but not when using Reflect.field

class Test
{
    public function new()
    {
        for(f in [foo, bar])
            for(h in [foo, bar])
                trace(Reflect.compareMethods(f, h));// says true when it should be true, false otherwise
               
        trace(Reflect.compareMethods(Reflect.field(this, "foo"), this.foo));//false
    }
    public function foo()
    {
    }
    public function bar()
    {
    }
    public static function main()
    {
        new Test();
    }
}


Strangely enough (while the first test works) the 'source' of Reflect.hx says:

    /**
        Compare two methods closures. Returns true if it's the same method of the same instance.
        Does not work on Neko platform.
    **/
    public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool;

Which documentation is correct?

Jan
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.compareMethods

Nicolas Cannasse
Le 05/04/2011 18:26, Jan Flanders a écrit :

> Hi,
>
> I'm a bit puzzled about the Reflect.compareMethods function. (I'm
> testing on the neko platform.)
>
> The documentation on the haxe site says: http://haxe.org/api/reflect
>
>     static function compareMethods( f1 : Dynamic
>     <http://haxe.org/api/dynamic>, f2 : Dynamic
>     <http://haxe.org/api/dynamic> ) : Bool <http://haxe.org/api/bool>
>     Compare two methods closures. Returns true if it's the same method
>     of the same instance.
> It seems to work but not when using Reflect.field

Yes. Reflect.field will not create a closure, it will directly return
the function-value. So if you have two Reflect.field accesses, you can
compare them directly with ==

There is no API to compare a function-value with a function-closure
right now, you'll have to create a closure by-hand by using appropriate
platform-specific code I guess.

> Which documentation is correct?

The online one. It's actually supported on Neko since 1.8.0

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.compareMethods

Jan_Flanders


On Wed, Apr 6, 2011 at 9:57 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 05/04/2011 18:26, Jan Flanders a écrit :
Hi,

I'm a bit puzzled about the Reflect.compareMethods function. (I'm
testing on the neko platform.)

The documentation on the haxe site says: http://haxe.org/api/reflect

   static function compareMethods( f1 : Dynamic
   <http://haxe.org/api/dynamic>, f2 : Dynamic
   <http://haxe.org/api/dynamic> ) : Bool <http://haxe.org/api/bool>

   Compare two methods closures. Returns true if it's the same method
   of the same instance.
It seems to work but not when using Reflect.field

Yes. Reflect.field will not create a closure, it will directly return the function-value. So if you have two Reflect.field accesses, you can compare them directly with ==

There is no API to compare a function-value with a function-closure right now, you'll have to create a closure by-hand by using appropriate platform-specific code I guess.

Which documentation is correct?

The online one. It's actually supported on Neko since 1.8.0

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org

Thanks for the explanation, I'm glad it is officially supported on Neko. :)
I rewrote a part of my code so I currently only need the one from the working example.

Jan


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.compareMethods

bubblebenj
I Nicolas,

I have one question about SPOD.

It is unclear to me why SPOD are persistent :
I mean they are persistent "because they are in a way store in a database" ?
or they are persistent "because they are still running somewhere on the server waiting for a call" ?

I'm asking this because I wonder, from a remotting connexion, if a have to update the SPOD to the database each time I use them and load then back the next time.
My guess is 'yes' but I'd rather get a statement on this.

Thanks
Ben

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.compareMethods

bubblebenj
Sorry I forgot the edit the subject

On Thu, Apr 7, 2011 at 6:56 AM, benjamin Dubois <[hidden email]> wrote:
I Nicolas,

I have one question about SPOD.

It is unclear to me why SPOD are persistent :
I mean they are persistent "because they are in a way store in a database" ?
or they are persistent "because they are still running somewhere on the server waiting for a call" ?

I'm asking this because I wonder, from a remotting connexion, if a have to update the SPOD to the database each time I use them and load then back the next time.
My guess is 'yes' but I'd rather get a statement on this.

Thanks
Ben


--
haXe - an open source web programming language
http://haxe.org