comparison src/luan/tools/WebServlet.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 cca4f8522893
children b1e87f1bcc13
comparison
equal deleted inserted replaced
85:b2551f00bc51 86:6db8f286fa6c
21 import luan.lib.HtmlLib; 21 import luan.lib.HtmlLib;
22 22
23 23
24 public class WebServlet extends HttpServlet { 24 public class WebServlet extends HttpServlet {
25 25
26 public static final String HTTP_SERVER = "http_server";
27
28 protected LuanState luanState = null; 26 protected LuanState luanState = null;
29 27
30 protected void loadLibs(LuanState luan) throws LuanException { 28 protected void loadLibs(LuanState luan) throws LuanException {
31 luan.load(BasicLib.NAME,BasicLib.LOADER); 29 luan.load(BasicLib.NAME,BasicLib.LOADER);
32 luan.load(PackageLib.NAME,PackageLib.LOADER); 30 luan.load(PackageLib.NAME,PackageLib.LOADER);
37 } 35 }
38 36
39 protected LuanState newLuanState() throws LuanException { 37 protected LuanState newLuanState() throws LuanException {
40 LuanState luan = LuanCompiler.newLuanState(); 38 LuanState luan = LuanCompiler.newLuanState();
41 loadLibs(luan); 39 loadLibs(luan);
42 PackageLib.require(luan,HTTP_SERVER); 40 HttpLib.load(luan);
43 Object fn = luan.global().get(HttpLib.FN_NAME);
44 if( !(fn instanceof LuanFunction) )
45 throw new LuanException( luan, LuanElement.JAVA, "function '"+HttpLib.FN_NAME+"' not defined" );
46 return luan; 41 return luan;
47 } 42 }
48 43
49 protected LuanState getLuanState(HttpServletRequest request) throws LuanException { 44 protected LuanState getLuanState(HttpServletRequest request) throws LuanException {
50 synchronized(this) { 45 synchronized(this) {
52 luanState = newLuanState(); 47 luanState = newLuanState();
53 } 48 }
54 return luanState.deepClone(); 49 return luanState.deepClone();
55 } 50 }
56 51
57 protected void service(HttpServletRequest request,HttpServletResponse response) 52 @Override protected void service(HttpServletRequest request,HttpServletResponse response)
58 throws ServletException, IOException 53 throws ServletException, IOException
59 { 54 {
60 try { 55 try {
61 LuanState luan = getLuanState(request); 56 LuanState luan = getLuanState(request);
62 HttpLib.service(luan,request,response); 57 HttpLib.service(luan,request,response);