Reflect.fields() and cpp

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

Reflect.fields() and cpp

alexander.konotop
In this function:
------------------------------------------------------------
public static function sortedDynamicvalues(input : Dynamic) :
  Array<String> {
    var keys : Array<String> = Reflect.fields(input);
    var output : Array<String> = new Array();
    for (key in keys.iterator())
    {
      output.push(Std.string(Reflect.field(input, key)));
    }
    output.sort(function(a,b)
      return Reflect.compare(a.toLowerCase(),b.toLowerCase())
    );
    return output;
  }
------------------------------------------------------------
the string:
-------------------------------------------------
var keys : Array<String> = Reflect.fields(input);
-------------------------------------------------
will work on js/neko/php but not on
cpp target. On cpp it just returns an empty array.

Actually I don't needed it in cpp, but it might be interesting for
somebody else.

P.S. This function returns an alphabetically sorted array of values,
of a Dynamic. It's suggested for this Dynamic to have only string-typed
members. (Like hash but not a hash :-))

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

Re: Reflect.fields() and cpp

Cauê W.
is input an anonymous object? If not, you must use Type.getInstanceFields(Type.getClass(input)) to get its fields

2011/3/7 Alexander Konotop <[hidden email]>
In this function:
------------------------------------------------------------
public static function sortedDynamicvalues(input : Dynamic) :
 Array<String> {
   var keys : Array<String> = Reflect.fields(input);
   var output : Array<String> = new Array();
   for (key in keys.iterator())
   {
     output.push(Std.string(Reflect.field(input, key)));
   }
   output.sort(function(a,b)
     return Reflect.compare(a.toLowerCase(),b.toLowerCase())
   );
   return output;
 }
------------------------------------------------------------
the string:
-------------------------------------------------
var keys : Array<String> = Reflect.fields(input);
-------------------------------------------------
will work on js/neko/php but not on
cpp target. On cpp it just returns an empty array.

Actually I don't needed it in cpp, but it might be interesting for
somebody else.

P.S. This function returns an alphabetically sorted array of values,
of a Dynamic. It's suggested for this Dynamic to have only string-typed
members. (Like hash but not a hash :-))

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


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

Re: Reflect.fields() and cpp

Tony Polinelli
This has bothered me for a while- why is this so? Shouldnt reflection work on all objects, anonymous + class instances? It is definately possible, and it would obviously only take 1 line of code to fix (check the type of object) + use existing func that you explained. 

Is this not a 'normal' feature for 'reflection'? i thought that was the whole idea of it - that classes can 'look' at themselves, and tell information about them.. like looking at a reflection - not just anonymous obj.



On Tue, Mar 8, 2011 at 7:05 AM, Cauê Waneck <[hidden email]> wrote:
is input an anonymous object? If not, you must use Type.getInstanceFields(Type.getClass(input)) to get its fields

2011/3/7 Alexander Konotop <[hidden email]>

In this function:
------------------------------------------------------------
public static function sortedDynamicvalues(input : Dynamic) :
 Array<String> {
   var keys : Array<String> = Reflect.fields(input);
   var output : Array<String> = new Array();
   for (key in keys.iterator())
   {
     output.push(Std.string(Reflect.field(input, key)));
   }
   output.sort(function(a,b)
     return Reflect.compare(a.toLowerCase(),b.toLowerCase())
   );
   return output;
 }
------------------------------------------------------------
the string:
-------------------------------------------------
var keys : Array<String> = Reflect.fields(input);
-------------------------------------------------
will work on js/neko/php but not on
cpp target. On cpp it just returns an empty array.

Actually I don't needed it in cpp, but it might be interesting for
somebody else.

P.S. This function returns an alphabetically sorted array of values,
of a Dynamic. It's suggested for this Dynamic to have only string-typed
members. (Like hash but not a hash :-))

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


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



--
Tony Polinelli
http://touchmypixel.com

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

Re: Reflect.fields() and cpp

Nicolas Cannasse
Le 07/03/2011 22:45, Tony Polinelli a écrit :
> This has bothered me for a while- why is this so? Shouldnt reflection
> work on all objects, anonymous + class instances? It is definately
> possible, and it would obviously only take 1 line of code to fix (check
> the type of object) + use existing func that you explained.

The main issue is performance.

While most platforms have an easy way of listing the variables of an
anonymous object, things are more difficult when you want to list
methods and other class vars that comes with the class prototype.

Please note that this is also two different kind of variables. Methods
might not be directly part of the object itself but part of his class
prototype.

So we have one simple Reflect.fields for anonymous objects and one more
complex getInstanceFields that does more work.

Best,
Nicolas

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