Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Actionscript syntax to Objective C

I have a game I wrote in Actionscript 3 I'm looking to port to iOS. The game has about 9k LOC spread across 150 classes, most of the classes are for data models, state handling and level generation all of which should be easy to port.

However, the thought of rejiggering the syntax by hand across all these files is none too appealing. Are there tools that can help me speed up this process?

I'm not looking for a magical tool here, nor am I looking for a cross compiler, I just want some help converting my source files.

like image 783
grapefrukt Avatar asked Oct 06 '10 08:10

grapefrukt


2 Answers

I don't know of a tool, but this is the way I'd try and attack your problem if there really is a lot of (simple) code to convert. I'm sure my suggestion is not that useful on parts of the code that are very flash-specific (all the DisplayObject stuff?) and also not that useful on lots of your logic. But it would be fun to build! :-)

Partial automatic conversion should be possible, especially if the objects are just 'data containers', watch out for bringing too much as3-idiom over to objective-c though, it might not always be a good fit.

Unless you want to create your own (semi) parser for as3 you'd need some sort of a parser, apparently FlexPMD has one (never used it), and there probably are others.

After getting your hands on a parser you have to find some way of suggesting to the system what parts could be converted automatically. You could try and add rules to the parser/generator script for the general case. For more specific cases I'd use custom metadata on the actual class/property/method, assuming a real as3 parser would correctly parse those.

Now part of your work will shift from hand-converting files to hand-annotating files, but that might be ok for you.

Have the parser parse your classes and define actions based on your metadata that will determine what kind of objective-c class to generate. If you get this working it could at least get you all your classes, their simple properties and method signatures (getting the body of the methods converted might be a bit too much to ask but you could include it as a comment so you'd have a nice reference while hand-translating).

PS: if you make this into a one way process be very sure you don't need to re-generate it later - it would be bad if you find out that you have been modifying the generated code and somehow need to re-generate all those classes -- that would mean you'll have to redo all your hard work!

like image 155
Simon Groenewolt Avatar answered Nov 05 '22 04:11

Simon Groenewolt


I've started putting a tool together to take the edge off the menial aspects of this process.

I'm trying to figure out if there's enough interest to make it clean and stable enough to release for others to use. I may just do it anyway.

http://meanwhileatthelab.blogspot.com.au/2012/08/automating-process-of-converting-as3-to.html

It's so far saving me a lot of time while porting one of my fairly large games from AS3 to objc.

like image 1
multiplang Avatar answered Nov 05 '22 05:11

multiplang