Mercurial Hosting > luan
view src/luan/tools/WebServlet.java @ 124:f537ff5e511d
minor cleanup
git-svn-id: https://luan-java.googlecode.com/svn/trunk@125 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 06 Jun 2014 03:41:04 +0000 |
parents | b1e87f1bcc13 |
children | 0149bdf98fd8 |
line wrap: on
line source
package luan.tools; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import luan.LuanState; import luan.LuanException; import luan.LuanRuntimeException; import luan.LuanFunction; import luan.LuanElement; import luan.interp.LuanCompiler; import luan.lib.HttpLib; import luan.lib.BasicLib; import luan.lib.PackageLib; import luan.lib.MathLib; import luan.lib.StringLib; import luan.lib.TableLib; import luan.lib.HtmlLib; public class WebServlet extends HttpServlet { protected LuanState luanState = null; protected LuanState newLuanState() throws LuanException { LuanState luan = LuanCompiler.newLuanState(); BasicLib.load(luan); PackageLib.load(luan); MathLib.load(luan); StringLib.load(luan); TableLib.load(luan); HtmlLib.load(luan); return luan; } @Override protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { try { synchronized(this) { if( luanState == null ) { luanState = newLuanState(); HttpLib.load(luanState); } } LuanState luan = luanState.deepClone(); service(request,response,luan); } catch(LuanException e) { throw new LuanRuntimeException(e); } } protected void service(HttpServletRequest request,HttpServletResponse response,LuanState luan) throws ServletException, IOException, LuanException { HttpLib.service(luan,request,response); } }