changeset 224:05eb2837ddbf

change LuanTable.put() to not return old value git-svn-id: https://luan-java.googlecode.com/svn/trunk@225 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 21 Jul 2014 09:27:06 +0000
parents a9fe265dbac3
children 7c768f63bbb3
files core/src/luan/AbstractLuanTable.java core/src/luan/LuanState.java core/src/luan/LuanTable.java core/src/luan/LuanTableImpl.java core/src/luan/impl/SetTableEntry.java web/src/luan/modules/web/HttpLuan.java
diffstat 6 files changed, 26 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
diff -r a9fe265dbac3 -r 05eb2837ddbf core/src/luan/AbstractLuanTable.java
--- a/core/src/luan/AbstractLuanTable.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/core/src/luan/AbstractLuanTable.java	Mon Jul 21 09:27:06 2014 +0000
@@ -30,7 +30,7 @@
 		return type() + ": " + Integer.toHexString(hashCode());
 	}
 
-	@Override public Object put(Object key,Object val) {
+	@Override public void put(Object key,Object val) {
 		throw new UnsupportedOperationException("can't put into a "+type());
 	}
 
diff -r a9fe265dbac3 -r 05eb2837ddbf core/src/luan/LuanState.java
--- a/core/src/luan/LuanState.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/core/src/luan/LuanState.java	Mon Jul 21 09:27:06 2014 +0000
@@ -99,6 +99,11 @@
 		return t==null ? null : t.get(op);
 	}
 
+	public final Object getHandler(String op,LuanTable table) {
+		LuanTable t = table.getMetatable();
+		return t==null ? null : t.get(op);
+	}
+
 	private static LuanTableImpl newMetatable() {
 		LuanTableImpl metatable = new LuanTableImpl();
 		try {
diff -r a9fe265dbac3 -r 05eb2837ddbf core/src/luan/LuanTable.java
--- a/core/src/luan/LuanTable.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/core/src/luan/LuanTable.java	Mon Jul 21 09:27:06 2014 +0000
@@ -9,7 +9,7 @@
 	public List<Object> asList();
 	public Map<Object,Object> asMap();
 	public Object get(Object key);
-	public Object put(Object key,Object val);
+	public void put(Object key,Object val);
 	public void insert(int pos,Object value);
 	public void add(Object value);
 	public Object remove(int pos);
diff -r a9fe265dbac3 -r 05eb2837ddbf core/src/luan/LuanTableImpl.java
--- a/core/src/luan/LuanTableImpl.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/core/src/luan/LuanTableImpl.java	Mon Jul 21 09:27:06 2014 +0000
@@ -208,7 +208,7 @@
 		return map.get(key);
 	}
 
-	@Override public Object put(Object key,Object val) {
+	@Override public void put(Object key,Object val) {
 		Integer iT = Luan.asInteger(key);
 		if( iT != null ) {
 			int i = iT - 1;
@@ -218,14 +218,13 @@
 						list.add(val);
 						mapToList();
 					}
-					return null;
+					return;
 				} else if( i>=0 && i<list.size() ) {
-					Object old = list.get(i);
 					list.set(i,val);
 					if( val == null ) {
 						listToMap(i);
 					}
-					return old;
+					return;
 				}
 			}
 		}
@@ -237,9 +236,9 @@
 			key = Double.valueOf(n.doubleValue());
 		}
 		if( val == null ) {
-			return map.remove(key);
+			map.remove(key);
 		} else {
-			return map.put(key,val);
+			map.put(key,val);
 		}
 	}
 
diff -r a9fe265dbac3 -r 05eb2837ddbf core/src/luan/impl/SetTableEntry.java
--- a/core/src/luan/impl/SetTableEntry.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/core/src/luan/impl/SetTableEntry.java	Mon Jul 21 09:27:06 2014 +0000
@@ -25,20 +25,17 @@
 		Object h;
 		if( t instanceof LuanTable ) {
 			LuanTable table = (LuanTable)t;
-			Object old;
-			try {
-				old = table.put(key,value);
-			} catch(IllegalArgumentException e) {
-				throw luan.bit(se).exception(e);
-			} catch(UnsupportedOperationException e) {
-				throw luan.bit(se).exception(e);
+			h = luan.getHandler("__newindex",table);
+			if( h==null || table.get(key)!=null ) {
+				try {
+					table.put(key,value);
+				} catch(IllegalArgumentException e) {
+					throw luan.bit(se).exception(e);
+				} catch(UnsupportedOperationException e) {
+					throw luan.bit(se).exception(e);
+				}
+				return;
 			}
-			if( old != null )
-				return;
-			h = luan.getHandler("__newindex",t);
-			if( h==null )
-				return;
-			table.put(key,old);
 		} else {
 			h = luan.getHandler("__newindex",t);
 			if( h==null )
diff -r a9fe265dbac3 -r 05eb2837ddbf web/src/luan/modules/web/HttpLuan.java
--- a/web/src/luan/modules/web/HttpLuan.java	Mon Jul 21 06:38:01 2014 +0000
+++ b/web/src/luan/modules/web/HttpLuan.java	Mon Jul 21 09:27:06 2014 +0000
@@ -182,18 +182,18 @@
 				return response.getHeaderNames().iterator();
 			}
 
-			@Override public Object put(Object key,Object val) {
+			@Override public void put(Object key,Object val) {
 				if( !(key instanceof String) )
 					throw new IllegalArgumentException("key must be string for headers table");
 				String name = (String)key;
 				if( val instanceof String ) {
 					response.setHeader(name,(String)val);
-					return null;
+					return;
 				}
 				Integer i = Luan.asInteger(val);
 				if( i != null ) {
 					response.setIntHeader(name,i);
-					return null;
+					return;
 				}
 				throw new IllegalArgumentException("value must be string or integer for headers table");
 			}
@@ -239,12 +239,11 @@
 				return new EnumerationIterator(request.getSession().getAttributeNames());
 			}
 
-			@Override public Object put(Object key,Object val) {
+			@Override public void put(Object key,Object val) {
 				if( !(key instanceof String) )
 					throw new IllegalArgumentException("key must be string for session attributes table");
 				String name = (String)key;
 				request.getSession().setAttribute(name,val);
-				return null;
 			}
 
 			@Override protected String type() {