Processing code preprocessor for different modes - new useful tool

Hello!

Having support for Android, Java and JavaScript, the Processing became really multi-platform language with thousands of possible applications.

Unfortunately, when it comes to more specific functions, as usage of sound or storage local data, the "multiplatformity" fails, since you need to write totally different code for JS and Java/Android. This is currently my problem, since I am working on a game, that aims to run at JS website, and as Android app.

Wouldn't be cool to have some conditional comments in code, that could be automagically commented/uncommented if you compile the code on different platform? Something like C preprocessor's #if command? For example:

void someMagicFunction() {

/*[Java]
someJavaMagic();
/**/

/*[JavaScript]
someJSHowToDo();
/**/

/*[Java]
someAndroidFunction();
/**/

}

I have started development a tool, that scans above code and, depending on mode, uncoments appropriate parts. So, running the tool while you're in Java mode will change the code to:

void someMagicFunction() {

/*[Java]*/
someJavaMagic();
/**/

/*[JavaScript]
someJSHowToDo();
/**/

/*[Java]
someAndroidFunction();
/**/

}

Therefore only parto for Java will be compiled.

This way, you can store different code variants for all three modes, and you don't manually change it anymore. Write once and just switch with two clicks!

The tool at rather early stage, but with full described functionality can be found here: https://docs.google.com/file/d/0BwyBGrLNFWABdDg1TFRqN0x2aUk (File → download)

Tagged:

Comments

  • Answer ✓

    Processing already got a pre-processor.
    It'd be perfect if devs would expand its functionally to include some basic directives like #define & #if.
    But it seems devs stopped being interested in the cross-mode-code for a long time now! :((

    Your initiative to mitigate this eternal "dire" situation is most welcome!!! :-bd

  • Maybe I'll take a look on the built-in pre-processor later and play with it a little to expand the functionality, maybe dev's will accept that ;) Currently, I got what I needed, so probably for now I'll kepp working on the main project...

Sign In or Register to comment.