Mercurial Hosting > luan
diff web/src/luan/modules/web/HttpLuan.java @ 175:bdbd4740121f
finish web server
git-svn-id: https://luan-java.googlecode.com/svn/trunk@176 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 23 Jun 2014 07:48:17 +0000 |
parents | 58c6ca5d4524 |
children | 2c08e7e27a70 |
line wrap: on
line diff
--- a/web/src/luan/modules/web/HttpLuan.java Mon Jun 23 02:57:50 2014 +0000 +++ b/web/src/luan/modules/web/HttpLuan.java Mon Jun 23 07:48:17 2014 +0000 @@ -28,16 +28,32 @@ public static final LuanFunction LOADER = new LuanFunction() { @Override public Object call(LuanState luan,Object[] args) { - return new LuanTable(); // starts empty + LuanTable module = new LuanTable(); + try { + addStatic( module, "new_luan_handler", LuanState.class ); + } catch(NoSuchMethodException e) { + throw new RuntimeException(e); + } + return module; } }; - public static void service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName) + private static void addStatic(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { + t.put( method, new LuanJavaFunction(HttpLuan.class.getMethod(method,parameterTypes),null) ); + } + + public static LuanHandler new_luan_handler(LuanState luan) { + return new LuanHandler(luan); + } + + public static boolean service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName) throws LuanException { LuanFunction fn; synchronized(luan) { - Object mod = PackageLuan.require(luan,modName); + Object mod = PackageLuan.load(luan,modName); + if( mod==null ) + return false; if( !(mod instanceof LuanTable) ) throw luan.exception( "module '"+modName+"' must return a table" ); LuanTable tbl = (LuanTable)mod; @@ -63,9 +79,9 @@ } } - LuanTable module = (LuanTable)luan.loaded().get("web.Http"); + LuanTable module = (LuanTable)luan.loaded().get("web/Http"); if( module == null ) - throw luan.exception( "module 'web.Http' not defined" ); + throw luan.exception( "module 'web/Http' not defined" ); HttpLuan lib = new HttpLuan(request,response); try { module.put( "request", lib.requestTable() ); @@ -80,6 +96,7 @@ } luan.call(fn,"<http>"); + return true; }