Int, Float, Dynamic as Dynamic return null???

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

Int, Float, Dynamic as Dynamic return null???

Ali Jaya Meilio Lie
hi list :D...
i have just found a interesting behavior.
my code looks like:

var d:Dynamic = 123; //Int
trace(Type.getClassName(Type.getClass(d))); // return null

and the other code :D

var d:Dynamic = 123.55; //Float
trace(Type.getClassName(Type.getClass(d))); // return null

and another code :p

var d:Dynamic = { };
trace(Type.getClassName(Type.getClass(d))); // return null

when i look in Type class,
this code lays in getClass function
if( cname == "null" || cname == "Object" || cname == "int" || cname ==
"Number" || cname == "Boolean" )
                return null;

and this code lays in getClassName function

if( c == null )
            return null;
        #if flash9
            var str : String = untyped
__global__["flash.utils.getQualifiedClassName"](c);
            switch( str ) {
            case "int": return "Int";
            case "Number": return "Float";
            case "Boolean": return "Bool";
            default:
            }
            return str.split("::").join(".");

OK..., i am confused.

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

Re: Int, Float, Dynamic as Dynamic return null???

Baluta Cristian
i don't really understand what you're doing there, but in your firsts samples you don't have any class, so seems to me normal to get null.

On Sat, Nov 22, 2008 at 7:14 PM, Ali Jaya Meilio <[hidden email]> wrote:
hi list :D...
i have just found a interesting behavior.
my code looks like:

var d:Dynamic = 123; //Int
trace(Type.getClassName(Type.getClass(d))); // return null

and the other code :D

var d:Dynamic = 123.55; //Float
trace(Type.getClassName(Type.getClass(d))); // return null

and another code :p

var d:Dynamic = { };
trace(Type.getClassName(Type.getClass(d))); // return null

when i look in Type class,
this code lays in getClass function
if( cname == "null" || cname == "Object" || cname == "int" || cname == "Number" || cname == "Boolean" )
              return null;

and this code lays in getClassName function

if( c == null )
          return null;
      #if flash9
          var str : String = untyped __global__["flash.utils.getQualifiedClassName"](c);
          switch( str ) {
          case "int": return "Int";
          case "Number": return "Float";
          case "Boolean": return "Bool";
          default:
          }
          return str.split("::").join(".");

OK..., i am confused.

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



--
Cristi
www.ralcr.com

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

Re: Int, Float, Dynamic as Dynamic return null???

Ali Jaya Meilio Lie
In reply to this post by Ali Jaya Meilio Lie
Oh sorry for unclear information.

If the value is String, the output of class' name is "String".
If the value is Array, the output of class' name is "Array".
Bv if the value is Dynamic, Int, Float, Bool, the output of class' name is "null"

I want to make JSON Encoder.
It take a Dynamic argument.
I want to check what its class' name, so i can parse it to string correctly :D

-alijaya

---- 
Sent using a Sony Ericsson mobile phone
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Int, Float, Dynamic as Dynamic return null???

Constantine-2
emplimentation of JSON - http://lib.haxe.org/p/hxJSON

also check method Type.typeof

Ali Jaya Meilio пишет:

> Oh sorry for unclear information.
>
> If the value is String, the output of class' name is "String".
> If the value is Array, the output of class' name is "Array".
> Bv if the value is Dynamic, Int, Float, Bool, the output of class' name is "null"
>
> I want to make JSON Encoder.
> It take a Dynamic argument.
> I want to check what its class' name, so i can parse it to string correctly :D
>
> -alijaya
>
> ---- 
Sent using a Sony Ericsson mobile phone


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

Re: Int, Float, Dynamic as Dynamic return null???

Nicolas Cannasse
In reply to this post by Ali Jaya Meilio Lie
Ali Jaya Meilio a écrit :
> hi list :D...
> i have just found a interesting behavior.

This is a feature, not a bug : Int , Float , Null , and Bool are not
considered to be instance of a given class in haXe, because this depends
on the platform.

However, since they are _declared_ as classes, Type.getClassName(Int) is
still working accordingly.

As suggested, use Type.typeof which is the best way to quickly know the
type of a value.

Best,
Nicolas

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