Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
85:b2551f00bc51 | 86:6db8f286fa6c |
---|---|
13 import javax.servlet.http.HttpSession; | 13 import javax.servlet.http.HttpSession; |
14 import org.slf4j.Logger; | 14 import org.slf4j.Logger; |
15 import org.slf4j.LoggerFactory; | 15 import org.slf4j.LoggerFactory; |
16 import luan.LuanFunction; | 16 import luan.LuanFunction; |
17 import luan.LuanState; | 17 import luan.LuanState; |
18 import luan.LuanTable; | |
18 import luan.LuanException; | 19 import luan.LuanException; |
19 import luan.interp.LuanCompiler; | |
20 import luan.lib.BasicLib; | 20 import luan.lib.BasicLib; |
21 import luan.lib.HtmlLib; | 21 import luan.lib.HtmlLib; |
22 | 22 |
23 | 23 |
24 public class WebShell extends HttpServlet { | 24 public class WebShell extends HttpServlet { |
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 Object[] eval(LuanState luan,String cmd) throws LuanException { | 31 protected LuanTable newEnvironment(LuanState luan) throws LuanException { |
32 return luan.eval(cmd,"WebShell"); | 32 return luan.newEnvironment(); |
33 } | 33 } |
34 | 34 |
35 protected void service(HttpServletRequest request,HttpServletResponse response) | 35 protected Object[] eval(LuanState luan,String cmd,LuanTable env) throws LuanException { |
36 return luan.eval(cmd,"WebShell",env); | |
37 } | |
38 | |
39 @Override protected void service(HttpServletRequest request,HttpServletResponse response) | |
36 throws ServletException, IOException | 40 throws ServletException, IOException |
37 { | 41 { |
38 PrintWriter out = response.getWriter(); | 42 PrintWriter out = response.getWriter(); |
39 HttpSession session = request.getSession(); | 43 HttpSession session = request.getSession(); |
40 | 44 |
56 LuanState luan = (LuanState)session.getValue("luan"); | 60 LuanState luan = (LuanState)session.getValue("luan"); |
57 if( luan==null ) { | 61 if( luan==null ) { |
58 luan = newLuanState(); | 62 luan = newLuanState(); |
59 session.putValue("luan",luan); | 63 session.putValue("luan",luan); |
60 } | 64 } |
65 LuanTable env = (LuanTable)session.getValue("env"); | |
66 if( env==null ) { | |
67 env = newEnvironment(luan); | |
68 session.putValue("env",env); | |
69 } | |
61 luan.out = new PrintStream(history); | 70 luan.out = new PrintStream(history); |
62 luan.global().put("request",request); | 71 env.put("request",request); |
63 luan.global().put("response",response); | 72 env.put("response",response); |
64 Object[] result = eval(luan,cmd); | 73 Object[] result = eval(luan,cmd,env); |
65 if( result.length > 0 ) { | 74 if( result.length > 0 ) { |
66 for( int i=0; i<result.length; i++ ) { | 75 for( int i=0; i<result.length; i++ ) { |
67 if( i > 0 ) | 76 if( i > 0 ) |
68 writer.write(" "); | 77 writer.write(" "); |
69 writer.write(HtmlLib.encode(luan.toString(null,result[i]))); | 78 writer.write(HtmlLib.encode(luan.toString(null,result[i]))); |