changeset 416:91af5337b9ae

add LuanMeta.__tostring()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Apr 2015 06:28:25 -0600
parents ce8e19567911
children a40e99cf0b0b
files core/src/luan/LuanBit.java core/src/luan/LuanMeta.java core/src/luan/LuanPropertyMeta.java lucene/src/luan/modules/lucene/FieldTable.java web/src/luan/modules/web/HttpServicer.java
diffstat 5 files changed, 43 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanBit.java	Thu Apr 30 06:04:17 2015 -0600
+++ b/core/src/luan/LuanBit.java	Thu Apr 30 06:28:25 2015 -0600
@@ -89,7 +89,13 @@
 
 	public String toString(Object obj) throws LuanException {
 		if( obj instanceof LuanTable ) {
-			LuanFunction fn = getHandlerFunction("__tostring",(LuanTable)obj);
+			LuanTable tbl = (LuanTable)obj;
+			Object h = luan.getHandler("__tostring",tbl);
+			if( h instanceof LuanMeta ) {
+				LuanMeta meta = (LuanMeta)h;
+				return meta.__tostring(luan,tbl);
+			}
+			LuanFunction fn = checkFunction(h);
 			if( fn != null )
 				return checkString( Luan.first( call(fn,"__tostring",new Object[]{obj}) ) );
 		}
--- a/core/src/luan/LuanMeta.java	Thu Apr 30 06:04:17 2015 -0600
+++ b/core/src/luan/LuanMeta.java	Thu Apr 30 06:28:25 2015 -0600
@@ -45,10 +45,17 @@
 		throw new UnsupportedOperationException();
 	}
 
+	protected abstract String type(LuanTable tbl);
+
+	public String __tostring(LuanState luan,LuanTable tbl) throws LuanException {
+		return type(tbl) + "-" + tbl;
+	}
+
 	public LuanTable newMetatable() {
 		LuanTable mt = new LuanTable();
 		mt.put( "__index", this );
 		mt.put( "__pairs", this );
+		mt.put( "__tostring", this );
 		if( canNewindex() )
 			mt.put( "__newindex", this );
 		return mt;
--- a/core/src/luan/LuanPropertyMeta.java	Thu Apr 30 06:04:17 2015 -0600
+++ b/core/src/luan/LuanPropertyMeta.java	Thu Apr 30 06:28:25 2015 -0600
@@ -17,6 +17,10 @@
 		return (LuanTable)tbl.getMetatable().get("set");
 	}
 
+	protected String type(LuanTable tbl) {
+		return (String)tbl.getMetatable().get("type");
+	}
+
 	@Override public Object __index(LuanState luan,LuanTable tbl,Object key) throws LuanException {
 		Object obj = getters(tbl).get(key);
 		if( obj == null )
@@ -62,6 +66,7 @@
 		LuanTable mt = super.newMetatable();
 		mt.put( "get", new LuanTable() );
 		mt.put( "set", new LuanTable() );
+		mt.put( "type", "property" );
 		return mt;
 	}
 
--- a/lucene/src/luan/modules/lucene/FieldTable.java	Thu Apr 30 06:04:17 2015 -0600
+++ b/lucene/src/luan/modules/lucene/FieldTable.java	Thu Apr 30 06:28:25 2015 -0600
@@ -56,9 +56,9 @@
 	@Override public final Iterator keys(LuanTable tbl) {
 		return map.keySet().iterator();
 	}
-/*
-	@Override protected String type() {
-		return "lucene-field-table";
+
+	@Override protected String type(LuanTable tbl) {
+		return "lucene-field";
 	}
-*/
+
 }
--- a/web/src/luan/modules/web/HttpServicer.java	Thu Apr 30 06:04:17 2015 -0600
+++ b/web/src/luan/modules/web/HttpServicer.java	Thu Apr 30 06:28:25 2015 -0600
@@ -131,11 +131,11 @@
 			@Override protected Iterator keys(LuanTable tbl) {
 				return new EnumerationIterator(request.getParameterNames());
 			}
-/*
-			@Override protected String type() {
-				return "request.parameters-table";
+
+			@Override protected String type(LuanTable tbl) {
+				return "request.parameters";
 			}
-*/
+
 		}.newTable();
 		tbl.put( "parameters", parameters );
 		add( tbl, "get_parameter_values", String.class );
@@ -148,11 +148,11 @@
 			@Override protected Iterator keys(LuanTable tbl) {
 				return new EnumerationIterator(request.getHeaderNames());
 			}
-/*
-			@Override protected String type() {
-				return "request.headers-table";
+
+			@Override protected String type(LuanTable tbl) {
+				return "request.headers";
 			}
-*/
+
 		}.newTable();
 		tbl.put( "headers", headers );
 		getters.put( "method", new LuanJavaFunction(
@@ -198,11 +198,11 @@
 					}
 				};
 			}
-/*
-			@Override protected String type() {
-				return "request.cookies-table";
+
+			@Override protected String type(LuanTable tbl) {
+				return "request.cookies";
 			}
-*/
+
 		}.newTable();
 		tbl.put( "cookies", cookies );
 
@@ -305,11 +305,11 @@
 				}
 				throw new IllegalArgumentException("value must be string or integer for headers table");
 			}
-/*
-			@Override protected String type() {
-				return "response.headers-table";
+
+			@Override protected String type(LuanTable tbl) {
+				return "response.headers";
 			}
-*/
+
 		}.newTable();
 		tbl.put( "headers", headers );
 		getters.put( "content_type", new LuanJavaFunction(
@@ -358,11 +358,11 @@
 				String name = (String)key;
 				request.getSession().setAttribute(name,val);
 			}
-/*
-			@Override protected String type() {
-				return "session.attributes-table";
+
+			@Override protected String type(LuanTable tbl) {
+				return "session.attributes";
 			}
-*/
+
 		}.newTable();
 		tbl.put( "attributes", attributes );
 		return tbl;