Is color a typedef or something else?

Hi everybody! So, I’ve had this question for a while now. It appears the type color in java is equivalent to the int type in every single way, to the point that the built-in java compile-time error checker (I wish I knew what it was called) literally just refers to it as “the type int”.

I figured for a while that somewhere in the Processing core source code, there was just a line of code that said typedef int color (but in Java). Today, however, I looked into it, and found there’s no such thing as typedef in java, nor is there any equivalent. The closest thing you can do is write a class that extends the class you want to typedef, but this does not work on int because it’s a primitive, and it does not work on Integer because it’s a final class. Furthermore, after taking the source code, grepping for the word “color”, and lightly skimming the results, I couldn’t really find anything that might clue me in to how this works. So, my question is, how did they do it? And, if possible, how could I do the same thing in my code?

Thank you!

1 Like

Java’s got exactly 8 primitive keywords and that’s it:

Processing’s keyword color is an alias to Java’s int; and it’s valid on “.pde” files only, not “.java”.

Processing IDE (PDE)'s “pre-processor” is responsible for transpiling all “.pde” files from a sketch project’s root folder into 1 “.java” file.

4 Likes

Hi @Math_Machine,

Just some further insight on how it works…

Cheers
— mnse

General:
https://www.antlr.org/about.html

Definition:

Transformation:

3 Likes

Yes

Recently I had a case with a PGraphics though where I had to use color() and not int to make it work