I found that I can compile and run the processing code by myself, and instance of processing object have print and println method (as well as all processing functions):
var sketch = Processing.compile(texarea.val());
var processing = new Processing(canvas[0]);
processing.print = function(str) { output.append('<span>' + str + '</span>'); };
processing.println = function(str) { processing.print(str + '\n'); };
sketch.attach(processing, Processing.prototype); // defaultScope is set to the Processing.prototype
sketch.onLoad(processing);
if (processing.setup) {
processing.setup();
processing.resetMatrix();
sketch.onSetup();
}
if (processing.draw) {
processing.redraw();
}
the code don't handle loops it was based on line 8514
var executeSketch = function(processing) {