jakarta-bsf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil Benn" <neil.b...@ziath.com>
Subject Usage of Eval
Date Tue, 06 Jun 2006 19:48:22 GMT
Hello,
 
            I am working with BSF and Jython (I'll move onto other
languages later - it's just the Jython/Python is the scriptng language I
am most used to).  I'm trying to implement a simple script to run a
method and get the result such as:
 
---
def test():
            return 1
test()
 
---
 
I was hoping that when I eval that using:
 
---
 
public void testRawJythonScript(){
            String strScript = "def test():\n";
            strScript += "\treturn 1\n";
            strScript += "test()\n";
            BSFManager objBM = new BSFManager();
            try{
                        Object objResult = objBM.eval("Jython", null, 0,
0, strScript);
                        System.out.println(objResult);
            }catch (BSFException eBSF){
                        eBSF.printStackTrace();
                        fail(eBSF.getMessage());
            }
}
 
---
 
  I would get the number 1 back (well in a PyObject but still 1).
However I get an exception:
 
---
 
junit.framework.AssertionFailedError: exception from Jython: Traceback
(innermost last):
  (no code object) at line 0
  File "<string>", line 1
            def test():
            ^
SyntaxError: invalid syntax
 
            at junit.framework.Assert.fail(Assert.java:47)
            at
uk.co.ziath.datapaq.server.scripting.test.BSFScriptProcessorTest.testRaw
JythonScript(BSFScriptProcessorTest.java:67)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at junit.framework.TestCase.runTest(TestCase.java:154)
            at junit.framework.TestCase.runBare(TestCase.java:127)
            at junit.framework.TestResult$1.protect(TestResult.java:106)
            at
junit.framework.TestResult.runProtected(TestResult.java:124)
            at junit.framework.TestResult.run(TestResult.java:109)
            at junit.framework.TestCase.run(TestCase.java:118)
            at junit.framework.TestSuite.runTest(TestSuite.java:208)
            at junit.framework.TestSuite.run(TestSuite.java:203)
            at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:478)
            at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
            at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)
 
---
 
            In addition my System.out repeats the top message a few
times, I've tried playing around with a few things but I can't
understand why BSF/Jython thinks this is bad code.  I would be eternally
grateful if someone could point me in the right direction! If this is
better asked on the Jython Users board then please let me know - ta.
 
            Thanks in advance.        
 
Cheers,
 
Neil

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message