comparison web/src/luan/modules/web/HttpLuan.java @ 221:ec016471c6eb

make LuanTable an interface git-svn-id: https://luan-java.googlecode.com/svn/trunk@222 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 17 Jul 2014 07:49:26 +0000
parents 92f5d74697f8
children b76fcb72d97d
comparison
equal deleted inserted replaced
220:61afe2a1ce96 221:ec016471c6eb
26 26
27 public final class HttpLuan { 27 public final class HttpLuan {
28 28
29 public static final LuanFunction LOADER = new LuanFunction() { 29 public static final LuanFunction LOADER = new LuanFunction() {
30 @Override public Object call(LuanState luan,Object[] args) { 30 @Override public Object call(LuanState luan,Object[] args) {
31 LuanTable module = new LuanTable(); 31 LuanTable module = Luan.newTable();
32 try { 32 try {
33 addStatic( module, "new_luan_handler", LuanState.class ); 33 addStatic( module, "new_luan_handler", LuanState.class );
34 } catch(NoSuchMethodException e) { 34 } catch(NoSuchMethodException e) {
35 throw new RuntimeException(e); 35 throw new RuntimeException(e);
36 } 36 }
112 this.request = request; 112 this.request = request;
113 this.response = response; 113 this.response = response;
114 } 114 }
115 115
116 private LuanTable requestTable() throws NoSuchMethodException { 116 private LuanTable requestTable() throws NoSuchMethodException {
117 LuanTable tbl = new LuanTable(); 117 LuanTable tbl = Luan.newTable();
118 tbl.put("java",request); 118 tbl.put("java",request);
119 add( tbl, "get_parameter", String.class ); 119 add( tbl, "get_parameter", String.class );
120 tbl.put( "get_header", new LuanJavaFunction( 120 tbl.put( "get_header", new LuanJavaFunction(
121 HttpServletRequest.class.getMethod("getHeader",String.class), request 121 HttpServletRequest.class.getMethod("getHeader",String.class), request
122 ) ); 122 ) );
135 ) ); 135 ) );
136 return tbl; 136 return tbl;
137 } 137 }
138 138
139 private LuanTable responseTable() throws NoSuchMethodException { 139 private LuanTable responseTable() throws NoSuchMethodException {
140 LuanTable tbl = new LuanTable(); 140 LuanTable tbl = Luan.newTable();
141 tbl.put("java",response); 141 tbl.put("java",response);
142 add( tbl, "send_redirect", String.class ); 142 add( tbl, "send_redirect", String.class );
143 add( tbl, "send_error", Integer.TYPE, String.class ); 143 add( tbl, "send_error", Integer.TYPE, String.class );
144 tbl.put( "contains_header", new LuanJavaFunction( 144 tbl.put( "contains_header", new LuanJavaFunction(
145 HttpServletResponse.class.getMethod("containsHeader",String.class), response 145 HttpServletResponse.class.getMethod("containsHeader",String.class), response
156 add( tbl, "text_writer" ); 156 add( tbl, "text_writer" );
157 return tbl; 157 return tbl;
158 } 158 }
159 159
160 private LuanTable cookieTable() throws NoSuchMethodException { 160 private LuanTable cookieTable() throws NoSuchMethodException {
161 LuanTable tbl = new LuanTable(); 161 LuanTable tbl = Luan.newTable();
162 tbl.put( "get", new LuanJavaFunction( 162 tbl.put( "get", new LuanJavaFunction(
163 HttpLuan.class.getMethod("get_cookie",String.class), this 163 HttpLuan.class.getMethod("get_cookie",String.class), this
164 ) ); 164 ) );
165 tbl.put( "set", new LuanJavaFunction( 165 tbl.put( "set", new LuanJavaFunction(
166 HttpLuan.class.getMethod("set_cookie", String.class, String.class, Boolean.TYPE, String.class), this 166 HttpLuan.class.getMethod("set_cookie", String.class, String.class, Boolean.TYPE, String.class), this
170 ) ); 170 ) );
171 return tbl; 171 return tbl;
172 } 172 }
173 173
174 private LuanTable sessionTable() throws NoSuchMethodException { 174 private LuanTable sessionTable() throws NoSuchMethodException {
175 LuanTable tbl = new LuanTable(); 175 LuanTable tbl = Luan.newTable();
176 tbl.put( "get_attribute", new LuanJavaFunction( 176 tbl.put( "get_attribute", new LuanJavaFunction(
177 HttpLuan.class.getMethod("get_session_attribute",String.class), this 177 HttpLuan.class.getMethod("get_session_attribute",String.class), this
178 ) ); 178 ) );
179 tbl.put( "set_attribute", new LuanJavaFunction( 179 tbl.put( "set_attribute", new LuanJavaFunction(
180 HttpLuan.class.getMethod("set_session_attribute",String.class, Object.class), this 180 HttpLuan.class.getMethod("set_session_attribute",String.class, Object.class), this