Loading...
Logo
Processing Forum
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)?

Replies(4)

Apart from hacky solutions (see previous forum threads), there is no way to find the Processing version. Of course this would be really useful for libraries, tutorials and sketches in general. However an enhancement request for a VERSION variable has been declined, see here. As Ben suggests, the solution is to stop supporting 1.x once 2.x is finally out and to file issues for things that break in 2.x.
Thanks for the pointer. Personally I think it is a shame there is no VERSION constant available. I don't think it necessarily forces any extra work on the core Processing developers simply to make a version number available (this is quite different to requiring all 2.x Processing core stuff to be consistent with previous 1.x versions). After all there is a versioning mechanism required for all libraries and indeed the PDE editor.

As it is, given the good year or so where there are 1.x and 2.x (albeit alpha and beta) versions available in parallel and the need to have commonly used libraries ready for full 2.x release, this is causing me real headaches and is slowing down my library development. I hate having to develop parallel versions of all my libraries.

Can you point to any of the hacky solutions in previous forum threads? I've tried searching but not found anything yet.
Thanks - that's very helpful (not sure why my search didn't bring that thread up).