From: Don S. <don...@gm...> - 2005-01-15 23:28:15
|
Hello, The current implementation of JythonEngine seems to be very selective about when to "unwrap" Python objects and return pure Java objects. The return value from call() is always unwrapped (and input arguments are wrapped appropriately). However, the return values from eval() and apply() are only unwrapped if the code returns a PyJavaInstance (i.e., not for PyString, PyInteger, etc.). This means that if a client of BSF wants to allow the user to use both Ruby and Python code, they must write some Python-specific Java code in order to extract the return values from Jython wrapper objects. Since the goal of BSF is to provide a language-independent abstraction layer which allows the user to switch languages at will, requiring them to import Jython-specific packages is obviously a bad thing. I've attached a patch that makes Jython's BSFEngine behave more like the other languages. I've CC'd the jython-dev list as I suspect they may have some input on this (with respect to backwards compatibility issues, etc.). How does everyone feel about this? Thanks, Don Index: src/org/apache/bsf/engines/jython/JythonEngine.java =================================================================== RCS file: /home/cvspublic/jakarta-bsf/src/org/apache/bsf/engines/jython/JythonEngine.java,v retrieving revision 1.8 diff -u -r1.8 JythonEngine.java --- src/org/apache/bsf/engines/jython/JythonEngine.java 14 Jun 2004 17:29:40 -0000 1.8 +++ src/org/apache/bsf/engines/jython/JythonEngine.java 15 Jan 2005 23:23:28 -0000 @@ -145,8 +145,8 @@ Object result = interp.eval ("bsf_temp_fn()"); - if (result != null && result instanceof PyJavaInstance) - result = ((PyJavaInstance)result).__tojava__(Object.class); + if (result != null && result instanceof PyObject) + result = unwrap((PyObject)result); return result; } catch (PyException e) { throw new BSFException (BSFException.REASON_EXECUTION_ERROR, @@ -161,8 +161,8 @@ Object script) throws BSFException { try { Object result = interp.eval (byteify(script.toString ())); - if (result != null && result instanceof PyJavaInstance) - result = ((PyJavaInstance)result).__tojava__(Object.class); + if (result != null && result instanceof PyObject) + result = unwrap((PyObject)result); return result; } catch (PyException e) { throw new BSFException (BSFException.REASON_EXECUTION_ERROR, |