Message6267

Author otmarhumbel
Recipients otmarhumbel
Date 2010-12-05.10:09:13
SpamBayes Score 2.24702e-09
Marked as misclassified No
Message-id <1291543753.83.0.666041624088.issue1681@psf.upfronthosting.co.za>
In-reply-to
Content
[submitted on behalf of Christian Blichmann]

Calling methods from an embedded Jython script does nothing when
using JSR-223 and Jython 2.5.2rc2, while Jython 2.2.1 just works fine.

- ------------- myscript/ScriptingTest.java -------------
package myscript;

import java.io.InputStream;
import java.io.InputStreamReader;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class ScriptingTest {
   public static void main(String[] args) {
       try {
           final ScriptEngineManager manager =
               new ScriptEngineManager();
           final ScriptEngine engine =
               manager.getEngineByName("python");

           final InputStream is =
               ScriptingTest.class.getResourceAsStream(
                       "/myscript/myscript.py");
           engine.eval(new InputStreamReader(is));
       } catch (final Exception e) {
           e.printStackTrace();
       }
   }
}
- ------------- myscript/PythonCallable.java -------------
package myscript;

public interface PythonCallable {
   String getAString();
   void callAVoid();
}
- ------------- myscript/myscript.py -------------
from myscript import PythonCallable as PythonCallable

class MyPythonCallable(PythonCallable):
   def getAString(self):
       return 'A string'

   def callAVoid(self):
       print 'Called a void method'

print 'getAString() returns: %s' % \
   MyPythonCallable().getAString()
print 'callAVoid():'
MyPythonCallable().callAVoid()
- ------------------------------------------------

Using Jython 2.2.1, I get:
 $ java -cp .:jython.jar:jython-engine.jar myscript.ScriptingTest
 getAString() returns: A string
 callAVoid():
 Called a void method
History
Date User Action Args
2010-12-05 10:09:13otmarhumbelsetrecipients: + otmarhumbel
2010-12-05 10:09:13otmarhumbelsetmessageid: <1291543753.83.0.666041624088.issue1681@psf.upfronthosting.co.za>
2010-12-05 10:09:13otmarhumbellinkissue1681 messages
2010-12-05 10:09:13otmarhumbelcreate