New as3 -> haxe (in haxe neko)

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

New as3 -> haxe (in haxe neko)

Tarwin Stroh-Spijer
So, I wrote a little utility to convert AS3 to haxe, to run as a neko command line utility. It does the following:

- changes any 4x spaces to tabs (needed for later cleanup)
- fixes package, opening and closing braces as well
- fixes classes to be haxe-like
- replaces all the void, Boolean, Number, including
- fixes Vectors and adds imports
- fixes arrays, adding <Dynamic> (don't think there's an easy way to actually define these properly
- fixes protected and internet defs
- makes all namespaces private and adds a "using" for a friend class
- fixes "const" and creates static inline vars
- fixes Error class (simply imports flash.Error if it's used)
- creates proper haxe getter/setters

- TODO: create "friend" class from namespaces info collected information (need help)
- TODO: move initial var setting from var definition to constructor (not for static inline of course)
- TODO: loops. No idea where to start this. Worried I'll simply break things. I guess this is my only real gripe with haxe as well, that there are no for(n;n;n) loops - annoying for long loops when you have to look at the end of the code to see what's happening to your vars!

So. Is this useful? Can anyone help me fix those last few things? Can anyone give advice on "friend" classes? Why does Away3DLite Haxe have both arcane_ns AND arcaneNS defined?

--------------------------------------------------------------------

Use

Simply run "neko As3ToHaxe.n -from <path of AS3> -to <path where you want hx files>

You can also add "-remove" if you want it to remove everything in the target (-to) path.


Regards,

Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________

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

As3ToHaxe.hx (16K) Download Attachment
make.hxml (52 bytes) Download Attachment
As3ToHaxe.n (99K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New as3 -> haxe (in haxe neko)

Cauê W.
hey tarwin! That's great work mate! : )

2011/3/14 Tarwin Stroh-Spijer <[hidden email]>
So, I wrote a little utility to convert AS3 to haxe, to run as a neko command line utility. It does the following:

- changes any 4x spaces to tabs (needed for later cleanup)
- fixes package, opening and closing braces as well
- fixes classes to be haxe-like
- replaces all the void, Boolean, Number, including
- fixes Vectors and adds imports
- fixes arrays, adding <Dynamic> (don't think there's an easy way to actually define these properly
- fixes protected and internet defs
- makes all namespaces private and adds a "using" for a friend class
- fixes "const" and creates static inline vars
- fixes Error class (simply imports flash.Error if it's used)
- creates proper haxe getter/setters

- TODO: create "friend" class from namespaces info collected information (need help)
- TODO: move initial var setting from var definition to constructor (not for static inline of course)
- TODO: loops. No idea where to start this. Worried I'll simply break things. I guess this is my only real gripe with haxe as well, that there are no for(n;n;n) loops - annoying for long loops when you have to look at the end of the code to see what's happening to your vars!

So. Is this useful? Can anyone help me fix those last few things? Can anyone give advice on "friend" classes? Why does Away3DLite Haxe have both arcane_ns AND arcaneNS defined?

--------------------------------------------------------------------

Use

Simply run "neko As3ToHaxe.n -from <path of AS3> -to <path where you want hx files>

You can also add "-remove" if you want it to remove everything in the target (-to) path.


Regards,

Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________

--
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
|  
Report Content as Inappropriate

Re: New as3 -> haxe (in haxe neko)

MarcWeber
In reply to this post by Tarwin Stroh-Spijer
For completeness you may want to add
https://github.com/geekrelief/as3tohaxe
to a list of related work within your documentation.

It was written in Haskell though.

Marc Weber

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

Re: New as3 -> haxe (in haxe neko)

jlm@justinfront.net
In reply to this post by Tarwin Stroh-Spijer
Tarwin 

This really useful.  I know some will complain and I hope you don't object, but I added it directly to the relevant haXe page as it can be a real show stopper and compiling neko is going to be the easiest for as3 developers and it's a great example of practical haXe. Since it's small might as well be featured on the page, rather than lost in a mailing list, and maybe a repository is over kill.


Someone on the forum wants as2 one... he's using haXe for flash lite and has lots of as2 libraries, but I will point him at that and hopefully....

Cheers

;j


On 14 Mar 2011, at 04:24, Tarwin Stroh-Spijer wrote:

So, I wrote a little utility to convert AS3 to haxe, to run as a neko command line utility. It does the following:

- changes any 4x spaces to tabs (needed for later cleanup)
- fixes package, opening and closing braces as well
- fixes classes to be haxe-like
- replaces all the void, Boolean, Number, including
- fixes Vectors and adds imports
- fixes arrays, adding <Dynamic> (don't think there's an easy way to actually define these properly
- fixes protected and internet defs
- makes all namespaces private and adds a "using" for a friend class
- fixes "const" and creates static inline vars
- fixes Error class (simply imports flash.Error if it's used)
- creates proper haxe getter/setters

- TODO: create "friend" class from namespaces info collected information (need help)
- TODO: move initial var setting from var definition to constructor (not for static inline of course)
- TODO: loops. No idea where to start this. Worried I'll simply break things. I guess this is my only real gripe with haxe as well, that there are no for(n;n;n) loops - annoying for long loops when you have to look at the end of the code to see what's happening to your vars!

So. Is this useful? Can anyone help me fix those last few things? Can anyone give advice on "friend" classes? Why does Away3DLite Haxe have both arcane_ns AND arcaneNS defined?

--------------------------------------------------------------------

Use

Simply run "neko As3ToHaxe.n -from <path of AS3> -to <path where you want hx files>

You can also add "-remove" if you want it to remove everything in the target (-to) path.


Regards,

Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________
<As3ToHaxe.hx><make.hxml><As3ToHaxe.n>--
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
|  
Report Content as Inappropriate

Re: New as3 -> haxe (in haxe neko)

Tarwin Stroh-Spijer
@jlm: That's fine! I'll be adding it as a touchmypixel proejct when I figure out these last things (help?!) and then push that as a haxelib. But happy to have it there ATM.

Best thing I could suggest for the AS2 guy is to write externs for them, and just load the SWF (in the current domain, just wait AS2 doesn't even have this does it?)

@Mark: I actually tried that haskell thing first. It was first really annoying to try and get it to compile (on windows the current haskell release is horribly broken for some libraries and hasn't been fixed in forever!) and when I finally got a compile it just chocked on anything I have it so not useful (and it's already documented hence I found it).

@Caue: Thanks - just glad to help. I've been running Molehill Away3D through it as my test bed, seeing as it has a bunch of complex stuff in there (or at least a lot of code). I think I might need you to explain the whole friend class thing to me though, especially the need for both arcane_ns AND arcaneNS methods?

Also, does anyone know if there would be any way to do smart things with vars defined as "Class" ?

Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________

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

Re: New as3 -> haxe (in haxe neko)

jlm@justinfront.net
> Also, does anyone know if there would be any way to do smart things  
> with vars defined as "Class" ?

I used in getting events across application domains that was as3 first  
but similar in haXe, you call a static method to get an instance of  
the event so you can then get store the class and then you can set up  
listeners it's fairly long winded, I prefer to use an onEnterFrame  
listening to a static var change... if your in a hurry its much  
simpler to setup.

I have been using this sort of stuff for openpyro parsing from xml,

         public static function getControls( ?o_:  
Hash<Class<UIControl>> = null ): Hash<Class<UIControl>>
         {

             if( o_ == null ) o_ = new Hash();
             o_.set( 'UIControl',    
org.openPyro.core.UIControl                     );
             o_.set( 'Button',        
org.openPyro.controls.Button                    ); ...

but does my head in parsing xml so only have as3 one working.

But since you can grab any static var across an application domain  
thinking of loading classes at runtime based on what's needed and  
storing the class as a static var

static var uiControl: Class = UIControl;

and then you can normally do something from memory like
var main = _untyped  
cast( _loader.applicationDomain.currentDomain( 'application.Main' ),  
MovieClip );
then do stuff with it?
Type.createInstance( Type.getClass(main.uiControl).getDefinition(),  
[] );
I can track down the details it normally takes a lot of trial an error.

In my loading structures I have a config file where I store references  
to classes like the main controller class..

        public inline static var ApplicationMain:    
Class<application.Main>         = application.Main;

so I only have to change the config class so I can have my normal main  
after loading never have to be changed..

        _localroot.addChild( Type.createInstance( ConfigData.ApplicationMain,  
[ _loadExternals.content ] ) );

But your question is a bit vague!



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

Re: New as3 -> haxe (in haxe neko)

jlm@justinfront.net

On 14 Mar 2011, at 06:14, [hidden email] wrote:

> and then you can normally do something from memory like
> var main = _untyped  
> cast( _loader.applicationDomain.currentDomain( 'application.Main' ),  
> MovieClip );
> then do stuff with it?
> Type.createInstance( Type.getClass(main.uiControl).getDefinition(),  
> [] );
> I can track down the details it normally takes a lot of trial an  
> error.

The code here is wrong I can post something more correct later if  
useful.


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

Re: New as3 -> haxe (in haxe neko)

Nicolas Cannasse
In reply to this post by Tarwin Stroh-Spijer
Le 14/03/2011 04:24, Tarwin Stroh-Spijer a écrit :
> So, I wrote a little utility to convert AS3 to haxe, to run as a neko
> command line utility. It does the following:

Nice ;)

Actually we were working on something of this kind together with Franco.
I wrote a complete AS3 parser from scratch and Franco was working on the
printer.

It's actually a bit better than a replaced-based engine since you have
access to the whole classes structures and can do very smart replacements.

Please check :
http://code.google.com/p/haxe/source/browse/#svn%2Fother%2Fas3hx

Best,
Nicolas

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

Re: New as3 -> haxe (in haxe neko)

Tarwin Stroh-Spijer
Hi,

I wasn't sure if it was working - is it? Not trying to compete, just trying to get something that works 90% of the way 100% of the time.

Is it doing getter/setter and namespaces yet?

Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: <a href="tel:%2B61%203%208060%205321" target="_blank">+61 3 8060 5321
_______________________


On Mon, Mar 14, 2011 at 7:54 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 14/03/2011 04:24, Tarwin Stroh-Spijer a écrit :

So, I wrote a little utility to convert AS3 to haxe, to run as a neko
command line utility. It does the following:

Nice ;)

Actually we were working on something of this kind together with Franco.
I wrote a complete AS3 parser from scratch and Franco was working on the printer.

It's actually a bit better than a replaced-based engine since you have access to the whole classes structures and can do very smart replacements.

Please check :
http://code.google.com/p/haxe/source/browse/#svn%2Fother%2Fas3hx

Best,
Nicolas


--
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
|  
Report Content as Inappropriate

Re: New as3 -> haxe (in haxe neko)

Nicolas Cannasse
Le 14/03/2011 18:46, Tarwin Stroh-Spijer a écrit :
> Hi,
>
> I wasn't sure if it was working - is it? Not trying to compete, just
> trying to get something that works 90% of the way 100% of the time.
>
> Is it doing getter/setter and namespaces yet?

I just wrote the parser, ask Franco for the Writer status ;)

Not trying to compete either, but I think that a parser-based
implementation should enable much more code transformations which would
result in more nice+working haXe code. Hope to see everybody interested
in AS3-to-haXe conversion contributing to it.

Best,
Nicolas

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

Re: New as3 -> haxe (in haxe neko)

Cauê W.
In reply to this post by Tarwin Stroh-Spijer
@Caue: Thanks - just glad to help. I've been running Molehill Away3D through it as my test bed, seeing as it has a bunch of complex stuff in there (or at least a lot of code). I think I might need you to explain the whole friend class thing to me though, especially the need for both arcane_ns AND arcaneNS methods?

Well, the need for those is actually to make up for a strange error that I had on away3dlite. Sometimes - I never could isolate this issue properly - the haXe compiler would think that the inline arcane calls were recursive inlines, so I couldn't be able to compile. I know this is an ugly workaround, but the thing is, that my other options were to use untyped (bad for strong typing), or non-inline calls (very bad for performance ;) ) If you need anything, just message me!

Also, does anyone know if there would be any way to do smart things with vars defined as "Class" ?

Class<Dynamic> ?


Cheers!
Cauê

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

Re: New as3 -> haxe (in haxe neko)

Franco Ponticelli
In reply to this post by Nicolas Cannasse
The writer is very basic so far and could receive a lot of love. I just started doing something that "writes an output" :). If anyone wants to contribute patches (or big chunks of the implementation) I will be happy to apply them.

Franco

On Mon, Mar 14, 2011 at 5:57 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 14/03/2011 18:46, Tarwin Stroh-Spijer a écrit :

Hi,

I wasn't sure if it was working - is it? Not trying to compete, just
trying to get something that works 90% of the way 100% of the time.

Is it doing getter/setter and namespaces yet?

I just wrote the parser, ask Franco for the Writer status ;)

Not trying to compete either, but I think that a parser-based implementation should enable much more code transformations which would result in more nice+working haXe code. Hope to see everybody interested in AS3-to-haXe conversion contributing to it.


Best,
Nicolas

--
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
|  
Report Content as Inappropriate

Re: New as3 -> haxe (in haxe neko)

hopewise
This post has NOT been accepted by the mailing list yet.
Hi Franco, I know this is an old post, but, I am curious to know if you have finished your writer to convert AS3 to haxe? what's the status after 2 years now ?
Loading...