What is the best way of detecting the Processing version at runtime?
in
Programming Questions
•
7 months ago
As a writer of Processing libraries I am increasingly having to adapt my library code to deal with differences between Processing 1.x and 2.x. For example, the event registration mechanism is now different for both with no backward/forward compatibility [e.g. 1.x =
pApplet.registerMouseEvent(this); 2.x =
pApplet.registerMethod("mouseEvent",this)
;]
I would like to be able to provide cross-version libraries rather than having to main two sets of parallel libraries, and I would normally do this by implementing a factory design pattern with an interface to the cross-platform common functionality. My problem though is that I need to be able to detect at runtime which version of the processing core is being used with the library so the factory can create the appropriate implementation. As far as I can see there is no obvious 'version' constant or method available for such detection. I note that there is a 'Base' class available in the IDE application that has a version, but this is no good for libraries that just use the core classes.
So what is the best way to detect the difference between 2.x and 1.x from the processing core at runtime (hacky solutions OK, but ideally something that would survive future changes in the core library)?
1