comparison src/luan/tools/WebServlet.java @ 77:4bf3d0c0b6b9

make LuanState cloneable git-svn-id: https://luan-java.googlecode.com/svn/trunk@78 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 15 Feb 2013 09:55:17 +0000
parents 97b03fc807ad
children 9df729fa4419
comparison
equal deleted inserted replaced
76:97b03fc807ad 77:4bf3d0c0b6b9
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"; 26 public static final String HTTP_SERVER = "http_server";
27 27
28 protected LuanState luanState = null;
29
28 protected void loadLibs(LuanState luan) throws LuanException { 30 protected void loadLibs(LuanState luan) throws LuanException {
29 luan.load(BasicLib.LOADER,BasicLib.NAME); 31 luan.load(BasicLib.LOADER,BasicLib.NAME);
30 luan.load(PackageLib.LOADER,PackageLib.NAME); 32 luan.load(PackageLib.LOADER,PackageLib.NAME);
31 luan.load(MathLib.LOADER,MathLib.NAME); 33 luan.load(MathLib.LOADER,MathLib.NAME);
32 luan.load(StringLib.LOADER,StringLib.NAME); 34 luan.load(StringLib.LOADER,StringLib.NAME);
34 luan.load(HtmlLib.LOADER,HtmlLib.NAME); 36 luan.load(HtmlLib.LOADER,HtmlLib.NAME);
35 } 37 }
36 38
37 protected void loadLuan(LuanState luan) throws LuanException { 39 protected void loadLuan(LuanState luan) throws LuanException {
38 PackageLib.require(luan,HTTP_SERVER); 40 PackageLib.require(luan,HTTP_SERVER);
39 Object fn = luan.global.get(HttpLib.FN_NAME); 41 Object fn = luan.global().get(HttpLib.FN_NAME);
40 if( !(fn instanceof LuanFunction) ) 42 if( !(fn instanceof LuanFunction) )
41 throw new LuanException( luan, LuanElement.JAVA, "function '"+HttpLib.FN_NAME+"' not defined" ); 43 throw new LuanException( luan, LuanElement.JAVA, "function '"+HttpLib.FN_NAME+"' not defined" );
42 } 44 }
43 45
44 protected LuanState newLuanState() throws LuanException { 46 protected LuanState newLuanState() throws LuanException {
46 loadLibs(luan); 48 loadLibs(luan);
47 loadLuan(luan); 49 loadLuan(luan);
48 return luan; 50 return luan;
49 } 51 }
50 52
51 protected LuanState getLuanState() throws LuanException { 53 protected LuanState getLuanState() throws LuanException {
52 return newLuanState(); 54 synchronized(this) {
55 if( luanState == null )
56 luanState = newLuanState();
57 }
58 return luanState.deepClone();
53 } 59 }
54 60
55 protected void service(HttpServletRequest request,HttpServletResponse response) 61 protected void service(HttpServletRequest request,HttpServletResponse response)
56 throws ServletException, IOException 62 throws ServletException, IOException
57 { 63 {