Workflow of Processing java application

Hello, I am trying to fix the issue #4663 and I had a few doubts about how the flow of control occurs in the Processing application as a whole (I am working in Eclipse). I know that everything associated with loading the application interface and other parts of the UI happen in the processing-app package and that the processing language itself is defined in the processing-core package. The java mode that is displayed by default and handles the compiling of the code is in the processing-java package. What I am trying to understand is how a global function in the processing language is actually executed behind the scenes. For example, the fill(int rgb) function is a global function and is defined in the PGraphics class in the processing-core package. How does the code reach there? I traced the flow to Runner class (through Base, PApplet, etc.) in the java package, that compiles the code and displays the output. But, where or which class handles the code line by line, understands that this is the fill() function so then calls the PGraphics class. Basically, I am saying is that if we add a new global function, for example just like fill(), how do we reach there? How do we make changes so that I can just write a function xxxxxx() in void draw() for example and it does something just like fill, stroke, etc.?

Comments

  • edited March 2017

    I believe the trick is that the pre-processor wraps the Processing sketch in a class that extends PApplet. See processing.mode.java.pdex.SourceUtils.wrapSketch for how this is done. That way when the code is compiled the "global" functions are no longer global but instead implicitly refer to the inherited methods defined in PApplet. Therefore, a good place to define global functions is probably in PApplet itself. For example, here is where the fill() function is defined.

Sign In or Register to comment.