From: Nick C. <ni...@sr...> - 2001-03-30 16:45:22
|
Hi, I'm trying to use Jython as a scripting language within an ide. The ide is for developing simulations with a Java framework, and the scripting is for scripting simulation behavoir (not ide behavoir). Ideally, I'd want the user to define a Java class through the ide and have the behavoir of such a class defined in python. Of course, there's lots of wrapping etc. going on here, but I'm thinking of generating bytecode whose source code would look something like the following: public class MyAgent { private PyFunction step; private int wealth = 0; public void step() { step.__call(...); } } where the PyFunction step has the wealth ivar available to it. The PyFunction would be the result of compiling whatever the user entered into the ide, for example: if wealth > 3: do_something() else: do_something_else() My question then is, is this possible? And if so, how do I create a PyFunction object and ensure that its namespace / calling frame contains the appropriate mappings - so that in the above example the PyFunction has the current value for wealth. Alternatively, I suppose I could treat the Java class as a proxy for a PyClass, so that any calls on the Java class are forwarded to the PyClass so: public void setWealth(int val) { target.__setattr__("wealth", new PyInteger(val)); } Perhaps the PyClass should be a PyInstance here though. At any rate, the question remains given some jython source code how can I get a PyFunction, PyClass, or PyInstance from within a Java application. thanks very much, Nick ps. If this is all woefully wrong-headed, any suggestions would be appreciated. n. -- Nick Collier Social Science Research Computing University of Chicago http://repast.sourceforge.net |