comparison src/luan/tools/WebShell.java @ 108:3c404a296995

make Package module more standard; return _ENV by default; add "import" statement; git-svn-id: https://luan-java.googlecode.com/svn/trunk@109 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 May 2014 03:21:54 +0000
parents 6ca02b188dba
children 2428ecfed375
comparison
equal deleted inserted replaced
107:dbf459397217 108:3c404a296995
25 private static final Logger logger = LoggerFactory.getLogger(WebShell.class); 25 private static final Logger logger = LoggerFactory.getLogger(WebShell.class);
26 26
27 protected LuanState newLuanState() throws LuanException { 27 protected LuanState newLuanState() throws LuanException {
28 return LuanState.newStandard(); 28 return LuanState.newStandard();
29 } 29 }
30 30 /*
31 protected LuanTable newEnvironment(LuanState luan) throws LuanException { 31 protected LuanTable newEnvironment(LuanState luan) throws LuanException {
32 return luan.newEnvironment(); 32 return luan.newEnvironment();
33 } 33 }
34 34 */
35 protected Object[] eval(LuanState luan,String cmd,LuanTable env) throws LuanException { 35 protected Object[] eval(LuanState luan,String cmd) throws LuanException {
36 return luan.eval(cmd,"WebShell",env); 36 return luan.eval(cmd,"WebShell",true);
37 } 37 }
38 38
39 @Override protected void service(HttpServletRequest request,HttpServletResponse response) 39 @Override protected void service(HttpServletRequest request,HttpServletResponse response)
40 throws ServletException, IOException 40 throws ServletException, IOException
41 { 41 {
60 LuanState luan = (LuanState)session.getValue("luan"); 60 LuanState luan = (LuanState)session.getValue("luan");
61 if( luan==null ) { 61 if( luan==null ) {
62 luan = newLuanState(); 62 luan = newLuanState();
63 session.putValue("luan",luan); 63 session.putValue("luan",luan);
64 } 64 }
65 LuanTable env = (LuanTable)session.getValue("env");
66 if( env==null ) {
67 env = newEnvironment(luan);
68 session.putValue("env",env);
69 }
70 luan.out = new PrintStream(history); 65 luan.out = new PrintStream(history);
66 LuanTable env = luan.global();
71 env.put("request",request); 67 env.put("request",request);
72 env.put("response",response); 68 env.put("response",response);
73 Object[] result = eval(luan,cmd,env); 69 Object[] result = eval(luan,cmd);
74 if( result.length > 0 ) { 70 if( result.length > 0 ) {
75 for( int i=0; i<result.length; i++ ) { 71 for( int i=0; i<result.length; i++ ) {
76 if( i > 0 ) 72 if( i > 0 )
77 writer.write(" "); 73 writer.write(" ");
78 writer.write(HtmlLib.encode(luan.JAVA.toString(result[i]))); 74 writer.write(HtmlLib.encode(luan.JAVA.toString(result[i])));