Message4995

Author emblemparade
Recipients emblemparade
Date 2009-08-06.05:19:43
SpamBayes Score 6.329246e-05
Marked as misclassified No
Message-id <1249535984.97.0.23490289182.issue1426@psf.upfronthosting.co.za>
In-reply-to
Content
In Subversion revision 6633.

The issue is that sometimes a ScriptEngine can be re-used, but called
with a different context. Why do this? Lots of reasons! In applications
that use scripts a lot, it's a waste of resources to recreate the
ScriptEngine all over again. Instead, it is reused, while only a
different context is used. This is how I've implemented in the
Scripturian project, and it works fine for every other JSR-223-compliant
engine supported (include Jython 2.2 with its JSR-223 support library).

This was quite easy to fix. I'm unsure how to submit a patch, but I hope
this will suffice! Here is PyScriptEngine with my addition:

    private Object eval(PyCode code, ScriptContext context) throws
ScriptException {
        try {
            interp.setIn(context.getReader());
            interp.setOut(context.getWriter());
            interp.setErr(context.getErrorWriter());
            List<Integer> scopes = context.getScopes();
            for (int scope : scopes) {
            	this.context.setBindings( context.getBindings( scope ),
scope );
            }
            return interp.eval(code).__tojava__(Object.class);
        } catch (PyException pye) {
            throw scriptException(pye);
        }
    }
History
Date User Action Args
2009-08-06 05:19:45emblemparadesetrecipients: + emblemparade
2009-08-06 05:19:44emblemparadesetmessageid: <1249535984.97.0.23490289182.issue1426@psf.upfronthosting.co.za>
2009-08-06 05:19:44emblemparadelinkissue1426 messages
2009-08-06 05:19:43emblemparadecreate