diff src/luan/tools/WebShell.java @ 86:6db8f286fa6c

_ENV is per module, not global git-svn-id: https://luan-java.googlecode.com/svn/trunk@87 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 27 Feb 2013 08:03:51 +0000
parents 4bf3d0c0b6b9
children 6ca02b188dba
line wrap: on
line diff
--- a/src/luan/tools/WebShell.java	Mon Feb 25 03:53:54 2013 +0000
+++ b/src/luan/tools/WebShell.java	Wed Feb 27 08:03:51 2013 +0000
@@ -15,8 +15,8 @@
 import org.slf4j.LoggerFactory;
 import luan.LuanFunction;
 import luan.LuanState;
+import luan.LuanTable;
 import luan.LuanException;
-import luan.interp.LuanCompiler;
 import luan.lib.BasicLib;
 import luan.lib.HtmlLib;
 
@@ -28,11 +28,15 @@
 		return LuanState.newStandard();
 	}
 
-	protected Object[] eval(LuanState luan,String cmd) throws LuanException {
-		return luan.eval(cmd,"WebShell");
+	protected LuanTable newEnvironment(LuanState luan) throws LuanException {
+		return luan.newEnvironment();
 	}
 
-	protected void service(HttpServletRequest request,HttpServletResponse response)
+	protected Object[] eval(LuanState luan,String cmd,LuanTable env) throws LuanException {
+		return luan.eval(cmd,"WebShell",env);
+	}
+
+	@Override protected void service(HttpServletRequest request,HttpServletResponse response)
 		throws ServletException, IOException
 	{
 		PrintWriter out = response.getWriter();
@@ -58,10 +62,15 @@
 						luan = newLuanState();
 						session.putValue("luan",luan);
 					}
+					LuanTable env = (LuanTable)session.getValue("env");
+					if( env==null ) {
+						env = newEnvironment(luan);
+						session.putValue("env",env);
+					}
 					luan.out = new PrintStream(history);
-					luan.global().put("request",request);
-					luan.global().put("response",response);
-					Object[] result = eval(luan,cmd);
+					env.put("request",request);
+					env.put("response",response);
+					Object[] result = eval(luan,cmd,env);
 					if( result.length > 0 ) {
 						for( int i=0; i<result.length; i++ ) {
 							if( i > 0 )