class not found UInt when compiling to JS with jeash

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

class not found UInt when compiling to JS with jeash

tom rhodes
Hi,

I've just made a little flash thing with haxe, and am trying to get it to compile to JS using jeash first before i try and get it working in normal JS with compiler switches and the like. i've already done a couple of more simple tests which compile fine to both flash and JS/jeash, so i'm sure my path to the jeash source is ok. i'm getting this error though now...

"Class not found: UInt"

when i replace all refs to UInt with Int it compiles fine though, i guess UInt is missing from jeash? or is it JS in general?

cheers,

tom.

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

Re: class not found UInt when compiling to JS with jeash

jlm@justinfront.net
UInt is only in flash..
        http://haxe.org/api/uint

rather than search and replace you could change haxe/std/StdTypes.hx  
line 43 to include a typedef for javascript target.

#if (flash9 || flash9doc || js )
/**
        The unsigned Int type is only defined for Flash9. It's currently
        handled the same as a normal Int.
**/
typedef UInt = Int
#end



On 20 Feb 2011, at 15:59, tom rhodes wrote:

> Hi,
>
> I've just made a little flash thing with haxe, and am trying to get  
> it to compile to JS using jeash first before i try and get it  
> working in normal JS with compiler switches and the like. i've  
> already done a couple of more simple tests which compile fine to  
> both flash and JS/jeash, so i'm sure my path to the jeash source is  
> ok. i'm getting this error though now...
>
> "Class not found: UInt"
>
> when i replace all refs to UInt with Int it compiles fine though, i  
> guess UInt is missing from jeash? or is it JS in general?
>
> cheers,
>
> tom.
> --
> 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: class not found UInt when compiling to JS with jeash

tom rhodes
aha, cool thanks for that :)


On 20 February 2011 16:39, [hidden email] <[hidden email]> wrote:
UInt is only in flash..
       http://haxe.org/api/uint

rather than search and replace you could change haxe/std/StdTypes.hx line 43 to include a typedef for javascript target.

#if (flash9 || flash9doc || js )
/**
       The unsigned Int type is only defined for Flash9. It's currently
       handled the same as a normal Int.
**/
typedef UInt = Int
#end




On 20 Feb 2011, at 15:59, tom rhodes wrote:

Hi,

I've just made a little flash thing with haxe, and am trying to get it to compile to JS using jeash first before i try and get it working in normal JS with compiler switches and the like. i've already done a couple of more simple tests which compile fine to both flash and JS/jeash, so i'm sure my path to the jeash source is ok. i'm getting this error though now...

"Class not found: UInt"

when i replace all refs to UInt with Int it compiles fine though, i guess UInt is missing from jeash? or is it JS in general?

cheers,

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


--
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: class not found UInt when compiling to JS with jeash

jlm@justinfront.net
Just rem if you hack you haXe lib make a note somewhere as this will be overwritten when you install a new version, so potentially it's really bad idea :) not sure if you can remap just a class, probably worth a try.

On 20 Feb 2011, at 16:56, tom rhodes wrote:

aha, cool thanks for that :)


On 20 February 2011 16:39, [hidden email] <[hidden email]> wrote:
UInt is only in flash..
       http://haxe.org/api/uint

rather than search and replace you could change haxe/std/StdTypes.hx line 43 to include a typedef for javascript target.

#if (flash9 || flash9doc || js )
/**
       The unsigned Int type is only defined for Flash9. It's currently
       handled the same as a normal Int.
**/
typedef UInt = Int
#end




On 20 Feb 2011, at 15:59, tom rhodes wrote:

Hi,

I've just made a little flash thing with haxe, and am trying to get it to compile to JS using jeash first before i try and get it working in normal JS with compiler switches and the like. i've already done a couple of more simple tests which compile fine to both flash and JS/jeash, so i'm sure my path to the jeash source is ok. i'm getting this error though now...

"Class not found: UInt"

when i replace all refs to UInt with Int it compiles fine though, i guess UInt is missing from jeash? or is it JS in general?

cheers,

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


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

--
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: how do you check the expected setter parameter type.

jlm@justinfront.net
In reply to this post by jlm@justinfront.net
I am using an external library and trying to set fields dynamically from some xml, I am in some cases guessing a type, by analyzing the string but this does not work well for Int's and Float's unless I always put the point in the xml, so I wanted to actually check the setter type at runtime, but not sure I can?

For instance an unset field returns null or NaN so I am lost as to how to process my string.

Type.getClassName(Type.getClass( Reflect.field( o, field ) ));

and worse still I don't want to change the external library so I can't use a getter.

public var source(null, setSource) : String;

I would rather an approach that does not use macros, as I may not be able to use the latest haXe always.

Currently I have...

package zpartan.generic.openpyroextensions;
    
    
    class StringToType
    {
        
        
        /**
        *   parses node attributes to an object  // still in as3 to convert...
        */
        /*
        public static function attributeObject( node: XML ): Hash
        {
            
            var out:    Hash = new Hash();
            var temp:   String;
            var nom:    String;
            var val:    Dynamic;
            
            for each( var attribute: XML in node.@* )
            {
                
                if( attribute.name() != 'name' )
                {
                    
                    temp        = attribute.toXMLString();
                    nom         = attribute.name();
                    val         = convertToCorrectType( temp );
                    out[ nom ]  = val;
                    
                }
                
            }
            
            return out;
            
        }
        */
        
        
        public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void
        {
            
            Reflect.setField( o, field, 
                                        convertToCorrectType( 
                                                                value,
                                                                Type.getClassName( 
                                                                    Type.getClass( Reflect.field( o, field ) )
                                                                ) 
                                        ) 
                                    );
            
        }
        
        
        // cast attribute from string to appropriate type if possible.
        public static function convertToCorrectType( str_: String, ?className: String = '' ): Dynamic
        {
                
                
                if( str_.charAt(0) == '[' )
                {
                    str_ = str_.substr( 1, str_.length - 2 );
                    var arr: Array<Dynamic> = str_.split(',');
                    for( all in arr )
                    {
                        
                        if( className == '' )
                        {
                            arr[ all ] = convertToCorrectTypeSimple( arr[ all ] );
                        }
                        else
                        {
                            arr[ all ] = convertToCorrectTypeSimple( arr[ all ], className );
                        }
                        
                    }
                    
                    return arr;
                    
                }
                
                return convertToCorrectTypeSimple( str_, className );
                
        }
        
        
        public static function convertToCorrectTypeSimple( str_: String, ?className: String = '' ): Dynamic
        {
            
            trace( 'class name is ' + className );
            /*
            if( className != '' )
            {
                switch...// intend to add code here depending on what the setter expects.
            }
            else
            {
            */
            
                var num = Std.parseFloat( str_ );
                if( Math.isNaN( num ) )
                {
                    //trace( 'setting as a number ' + str_ );
                    return num;
                }
                var lowerCase = str_.toLowerCase();
                if( lowerCase == 'true' )
                {
                    return true;
                }
                if( lowerCase == 'false' )
                {
                    return false;
                }
                
            //}
            
            return str_;
            
        }
        
        
    }
    

On 20 Feb 2011, at 16:39, [hidden email] wrote:

UInt is only in flash..
http://haxe.org/api/uint

rather than search and replace you could change haxe/std/StdTypes.hx line 43 to include a typedef for javascript target.

#if (flash9 || flash9doc || js )
/**
The unsigned Int type is only defined for Flash9. It's currently
handled the same as a normal Int.
**/
typedef UInt = Int
#end



On 20 Feb 2011, at 15:59, tom rhodes wrote:

Hi,

I've just made a little flash thing with haxe, and am trying to get it to compile to JS using jeash first before i try and get it working in normal JS with compiler switches and the like. i've already done a couple of more simple tests which compile fine to both flash and JS/jeash, so i'm sure my path to the jeash source is ok. i'm getting this error though now...

"Class not found: UInt"

when i replace all refs to UInt with Int it compiles fine though, i guess UInt is missing from jeash? or is it JS in general?

cheers,

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


--
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: how do you check the expected setter parameter type.

jlm@justinfront.net
You can get XML back in flash about a class from the player... would that be my best approach will that cover setter parameter types?

On 20 Feb 2011, at 17:40, jlm wrote:

I am using an external library and trying to set fields dynamically from some xml, I am in some cases guessing a type, by analyzing the string but this does not work well for Int's and Float's unless I always put the point in the xml, so I wanted to actually check the setter type at runtime, but not sure I can?

For instance an unset field returns null or NaN so I am lost as to how to process my string.

Type.getClassName(Type.getClass( Reflect.field( o, field ) ));

and worse still I don't want to change the external library so I can't use a getter.

public var source(null, setSource) : String;

I would rather an approach that does not use macros, as I may not be able to use the latest haXe always.

Currently I have...

package zpartan.generic.openpyroextensions;
    
    
    class StringToType
    {
        
        
        /**
        *   parses node attributes to an object  // still in as3 to convert...
        */
        /*
        public static function attributeObject( node: XML ): Hash
        {
            
            var out:    Hash = new Hash();
            var temp:   String;
            var nom:    String;
            var val:    Dynamic;
            
            for each( var attribute: XML in node.@* )
            {
                
                if( attribute.name() != 'name' )
                {
                    
                    temp        = attribute.toXMLString();
                    nom         = attribute.name();
                    val         = convertToCorrectType( temp );
                    out[ nom ]  = val;
                    
                }
                
            }
            
            return out;
            
        }
        */
        
        
        public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void
        {
            
            Reflect.setField( o, field, 
                                        convertToCorrectType( 
                                                                value,
                                                                Type.getClassName( 
                                                                    Type.getClass( Reflect.field( o, field ) )
                                                                ) 
                                        ) 
                                    );
            
        }
        
        
        // cast attribute from string to appropriate type if possible.
        public static function convertToCorrectType( str_: String, ?className: String = '' ): Dynamic
        {
                
                
                if( str_.charAt(0) == '[' )
                {
                    str_ = str_.substr( 1, str_.length - 2 );
                    var arr: Array<Dynamic> = str_.split(',');
                    for( all in arr )
                    {
                        
                        if( className == '' )
                        {
                            arr[ all ] = convertToCorrectTypeSimple( arr[ all ] );
                        }
                        else
                        {
                            arr[ all ] = convertToCorrectTypeSimple( arr[ all ], className );
                        }
                        
                    }
                    
                    return arr;
                    
                }
                
                return convertToCorrectTypeSimple( str_, className );
                
        }
        
        
        public static function convertToCorrectTypeSimple( str_: String, ?className: String = '' ): Dynamic
        {
            
            trace( 'class name is ' + className );
            /*
            if( className != '' )
            {
                switch...// intend to add code here depending on what the setter expects.
            }
            else
            {
            */
            
                var num = Std.parseFloat( str_ );
                if( Math.isNaN( num ) )
                {
                    //trace( 'setting as a number ' + str_ );
                    return num;
                }
                var lowerCase = str_.toLowerCase();
                if( lowerCase == 'true' )
                {
                    return true;
                }
                if( lowerCase == 'false' )
                {
                    return false;
                }
                
            //}
            
            return str_;
            
        }
        
        
    }
    

On 20 Feb 2011, at 16:39, [hidden email] wrote:

UInt is only in flash..
http://haxe.org/api/uint

rather than search and replace you could change haxe/std/StdTypes.hx line 43 to include a typedef for javascript target.

#if (flash9 || flash9doc || js )
/**
The unsigned Int type is only defined for Flash9. It's currently
handled the same as a normal Int.
**/
typedef UInt = Int
#end



On 20 Feb 2011, at 15:59, tom rhodes wrote:

Hi,

I've just made a little flash thing with haxe, and am trying to get it to compile to JS using jeash first before i try and get it working in normal JS with compiler switches and the like. i've already done a couple of more simple tests which compile fine to both flash and JS/jeash, so i'm sure my path to the jeash source is ok. i'm getting this error though now...

"Class not found: UInt"

when i replace all refs to UInt with Int it compiles fine though, i guess UInt is missing from jeash? or is it JS in general?

cheers,

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


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

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


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