You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by sa...@opensource.lk on 2004/05/10 06:54:27 UTC

[PATCH]iexec() implementation for the JPython Engine

Dear All,

Please accept this patch which is diff which implements the iexec() method
and sets the standard output and err streams properly

Regards !!

Sanka Samaranayake <sa...@opensource.lk>

***********************************************************************
***********************************************************************



--- JPythonEngine.java	2004-04-08 16:50:42.000000000 +0600
+++ JPythonEngineModified.java	2004-05-02 00:32:46.000000000 +0600
@@ -141,6 +141,10 @@

 	// create an interpreter
 	interp = new PythonInterpreter ();
+
+	//ensures that the output and err streams are redirected correctly
+	interp.setOut(System.out);
+	interp.setErr(System.err);

 	// register the mgr with object name "bsf"
 	interp.set ("bsf", new BSFFunctions (mgr, this));
@@ -165,4 +169,25 @@
 	}
 	return result;
   }
+
+  public void iexec(String source, int lineNo, int columnNo, Object
script) throws BSFException{
+  	// implementation of this method differs to exec() only in that it
executes
+  	// the code upto the first new line character
+
+  	String scriptStr = script.toString();
+  	int index = scriptStr.indexOf("\n");
+
+  	if (index > -1){
+  		scriptStr = scriptStr.substring(0,index);
+  	}
+
+  	try{
+  		interp.exec(scriptStr.toString());
+
+  	}catch(PyException pye){
+  		throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
+				"exception in jpython "+pye,pye);
+  	}
+
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org