[haXe] Bugfix proposal: Int/Number deserialization in SWHX AS2
deserializer.
Ian Thomas
ian at eirias.net
Mon Apr 23 14:53:41 CEST 2007
Stefan,
I'm not too sure about that. You're testing isNaN against a
character code, not a digit, so I'm not clear why it helps? Surely
buf.charCodeAt must either return NULL or a number? How on earth is c
getting to be NaN?
I don't doubt that it helps, but I'm very puzzled as to why it works
out that way. :-) I'm wondering whether there's an error in
buf.charCodeAt (since I think it should return NULL - if we've gone
over the buffer length - or number).
Ian
On 4/23/07, Stefan Thurnherr <stefan.thurnherr at gmail.com> wrote:
> Hi haXers,
>
> When using synchronous communication between a haXe neko layer and an
> AS Flash GUI layer, I found that a return value of type Int is not
> possible at the haXe neko layer. While waiting for the return value my
> Flash GUI hangs. After a moment I get the "...script in this movie is
> causing MM Flash Player 8 to run slowly. ...".
>
> My AS Flash code (txtLog being a Dynamic TextField on stage):
>
> var arg0:Number = Math.round(Math.random() * 20);
> var arg1:Number = Math.round(Math.random() * 20);
> txtLog.text += "\nSubmitting [" + arg0 + "]+[" + arg1 + "].";
> var res:Object = swhx.Api.call("App.testAdd", arg0, arg1);
> txtLog.text += "\n -> got result: [" + res + "].";
>
>
> My haXe neko code:
>
> public static function testAdd(arg0:Int, arg1:Int):Int {
> var res:Int = arg0 + arg1;
> //systools.Dialogs.message("App::testAdd", "Calculating [" + arg0 +
> "] + [" + arg1 + "]\n ... \nthat makes [" + res + "], easy!",
> false);
> return (res);
> }
>
> If the return value type is changed to String it works perfectly. So
> the problem lies with the serialization/deserialization of Int
> arguments. I think the problem actually lies in the readDigits()
> method in haxe-1.12-win/lib/swhx/1,0,5,8/api/actionscript/AS2/swhx. A
> check for isNaN(c) should be added, otherwise the deserialization
> while loop runs forever. The check could for instance be added as
> follows:
>
> function readDigits(): Number {
> var k = 0;
> var s = false;
> var fpos = pos;
> while( true ) {
> var c = buf.charCodeAt(pos);
> consoleLog("\ngoing on with charCode [" + c + "] at pos [" + pos + "]...");
> if( c == null )
> break;
> if( c == 45 ) { // negative sign
> if( pos != fpos )
> break;
> s = true;
> pos++;
> continue;
> }
> if ( isNaN(c) ) //added isNaN check.
> break;
> c -= 48;
> if( c < 0 || c > 9 )
> break;
> k = k * 10 + c;
> pos++;
> }
> if( s )
> k *= -1;
> return k;
> }
>
> HTH,
> stefan.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
More information about the Haxe
mailing list