diff src/luan/modules/http/HttpServicer.java @ 796:6b8ea0a9b7c9

remove LuanMeta
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 05 Sep 2016 19:52:49 -0600
parents 60661a8e738c
children 9eccfede1094
line wrap: on
line diff
--- a/src/luan/modules/http/HttpServicer.java	Mon Sep 05 16:32:55 2016 -0600
+++ b/src/luan/modules/http/HttpServicer.java	Mon Sep 05 19:52:49 2016 -0600
@@ -28,7 +28,7 @@
 import luan.LuanFunction;
 import luan.LuanException;
 import luan.LuanTable;
-import luan.LuanPropertyMeta;
+//import luan.LuanPropertyMeta;
 import luan.LuanCloner;
 import luan.modules.PackageLuan;
 import luan.modules.IoLuan;
@@ -126,6 +126,7 @@
 					if( filename == null ) {
 						value = new String(part.getBytes());
 					} else {
+/*
 						LuanTable partTbl = LuanPropertyMeta.INSTANCE.newTable();
 						partTbl.rawPut("filename",filename);
 						partTbl.rawPut("content_type",part.getContentType());
@@ -141,6 +142,28 @@
 								}
 							}
 						} );
+*/
+						LuanTable partTbl = new LuanTable();
+						partTbl.rawPut("filename",filename);
+						partTbl.rawPut("content_type",part.getContentType());
+						LuanTable mt = new LuanTable();
+						partTbl.setMetatable(mt);
+						mt.rawPut( "__index", new LuanFunction() {
+							@Override public Object call(LuanState luan,Object[] args) throws LuanException {
+								Object key = args[1];
+								if( "content".equals(key) ) {
+									try {
+										InputStream in = part.getInputStream();
+										byte[] content = Utils.readAll(in);
+										in.close();
+										return content;
+									} catch(IOException e) {
+										throw new RuntimeException(e);
+									}
+								}
+								return null;
+							}
+						} );
 						value = partTbl;
 					}
 					LuanTable list = (LuanTable)parametersTbl.rawGet(name);