From: Neil B. <nei...@zi...> - 2006-12-07 18:41:50
|
Hello, Whoops, no I didn't have it working - ran the wrong test (bit tired that day). The issue is that I can't use objInterp.exec(strScript) as exec doesn't return an object - it just returns void. The current way I have to do register a return value, tell the user to set the result to that value, get it out and then deregister that value inside my script. That works but it is very different for the user as they have to do thing differently when coding Jython extensions to the system than a ruby extension (haven't tried groovy yet). From what I can see - I'm stuck here, can anyone point me to a potential solution (I'm fairly experienced in CPython as I use it in my day job and code Java in the evening - contrary to most people ;) )? Thanks, in advance for your help. Cheers, Neil --- Neil Benn CEO Ziath Ltd http://www.ziath.com -----Original Message----- From: jyt...@li... [mailto:jyt...@li...] On Behalf Of Sidharth Kuruvila Sent: 04 December 2006 22:53 To: jyt...@li... Subject: Re: [Jython-users] Use of eval Hi Ben, eval is meant for expressions. What you want to use is exec Object objResult = objInterp.exec(strScript); On 05-Dec-06, at 2:48 AM, Neil Benn wrote: Hello, I am trying to evaluate a script which runs as follows (using both BSF and JYthonInterp does the same thing): --- String strScript = "def test():\n"; strScript += "\treturn 1\n"; strScript += "test()"; Object objResult = objInterp.eval(strScript); --- However I get the following traceback (this is when run from JythonInterp), I've snipped the bottom bit off because it is in the unit test code Traceback (innermost last): (no code object) at line 0 SyntaxError: ('invalid syntax', ('<string>', 1, 1, 'def test():')) at org.python.core.parser.fixParseError(parser.java) at org.python.core.parser.parse(parser.java) at org.python.core.Py.compile_flags(Py.java) at org.python.core.Py.compile_flags(Py.java) at org.python.core.__builtin__.eval(__builtin__.java) at org.python.core.__builtin__.eval(__builtin__.java) at org.python.util.PythonInterpreter.eval(PythonInterpreter.java) at uk.co.ziath.datapaq.server.scripting.JythonScriptProcessor.evaluateScrip t(JythonScriptProcessor.java:76) at uk.co.ziath.datapaq.server.scripting.test.JythonScriptProcessorTest.test MethodJythonScript(JythonScriptProcessorTest.java:75) <snip> --- When I attempt to run a simple script such as 3* 4 and evaluate it, I get back 12 as I would expect. However it seems that any multi-line script fails on me. Is it true that I cannot use a multi-line script in an evaluate statement (I know I can do it in an execute statement)? Thanks for your help. Cheers, Neil --- Neil Benn CEO Ziath Ltd http://www.ziath.com ------------------------------------------------------------------------ - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVD EV_______________________________________________> &p=sourceforge&CID=DEVDEV_______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |