Hi everyone, I come up an idea about cross-mode libraries. The way below may make it works.
Maybe we could try out Mozilla's Rhino script engine to help building cross-mode libraries. That is, while some guys have done his library in JavaScript, we could make it possible to execute the libraries on both browsers and on Processing in Java mode. The Processing itself can provide fundemental methods for libraries written in JavaScript via script engine. Before running in Java mode, Processing loads the JavaScript core functions by executing it in a script engine, then loads the libraries one-by-one via a script engine as well. Finally, let the script engine (or providing some functions) available to be available for users.
This is rough description of the process in Java mode. Note that the "core js libs" can be some methods helping creating graphs on the canvas like line(), arc(), etc. The libraries loaded afterwards can only make use of the functions loaded in the "core js libs".
1. load core js libs (in JS engine)
2. load libraries from 3rd party providers (in JS engine)
3. provide objects or functions for users
While in a browser, we should provide a "core js libs" as well, which should provide the same interface in Java mode. The way it implements graphing may differ from the one in Java mode.
1. generate html files with core js libs.
2. insert the 3rd party libraries in the HTML source
3. run in a browser
In short, the core js libs may provide methods like arc(), line(), print(), etc. They have different implementation under JS mode and Java mode. The libraries in JS can only make use of these resources. For instance, if processing is going to provide a method send() to send a HTTP request, it could be done with the java.net package in Java mode, while it can be done via XMLHttpRequest under JS mode.
There are some advantages and drawbacks of this idea listed below.
(+) Developers can build their library once, and it will be available on both JS mode and Java mode.
(-) The 3rd party libraries must avoid methods not provided by core libs. For example, 'alert()' and 'document' are not available since they're not defined in Rhino script engine.
I know applying script engine is not an easy work, especially making a good core library interface and the capability on both browsers and the script engine. I would focus on the goal to build a good environment for the script engine (methods interfaces, security issues, etc). I'm glad if you give some suggestions (even whether it is a good idea or not) . Thanks.
About me,
I'm a undergraduate student of Department of Computer Science and Intelligence Engineering in Nation Taiwan University (freshman). I can do programming in Java and web pages languages (HTML, CSS, JavaScipt) fluently. I used Processing before with SimpleOpenNI, a tool to handle body actions, and Swing library to finish a Sudoku solver with GUI. This is the first time I engage in a open source project, of course, I'm new to GSoC as well. I'll appreciate you can give me some suggestions.