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.
CEO Ziath Ltd
From: firstname.lastname@example.org [mailto:email@example.com] On Behalf Of Sidharth Kuruvila
Sent: 04 December 2006 22:53
Subject: Re: [Jython-users] Use of eval
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:
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():'))
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.
CEO Ziath Ltd
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
Jython-users mailing list