diff core/src/luan/LuanTable.java @ 575:7c3ad6db8ac3

make LuanState.JAVA private
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 13 Jul 2015 18:34:31 -0600
parents f1601a4ce1aa
children 60c549d43988
line wrap: on
line diff
--- a/core/src/luan/LuanTable.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/LuanTable.java	Mon Jul 13 18:34:31 2015 -0600
@@ -11,11 +11,6 @@
 import java.util.Comparator;
 import java.util.Set;
 import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.regex.Pattern;
-import luan.modules.StringLuan;
-import luan.modules.BinaryLuan;
-import luan.modules.JavaLuan;
 
 
 public final class LuanTable implements DeepCloneable {
@@ -92,23 +87,23 @@
 		return list!=null ? list : Collections.emptyList();
 	}
 
-	public String toString(LuanBit bit) throws LuanException {
+	public String toString(LuanState luan) throws LuanException {
 		Object h = getHandler("__to_string");
 		if( h == null )
 			return rawToString();
 		if( h instanceof LuanMeta ) {
 			LuanMeta meta = (LuanMeta)h;
-			return meta.__to_string(bit.luan,this);
+			return meta.__to_string(luan,this);
 		}
-		LuanFunction fn = bit.checkFunction(h);
-		return bit.checkString( Luan.first( bit.call(fn,"__to_string",new Object[]{this}) ) );
+		LuanFunction fn = luan.checkFunction(h);
+		return luan.checkString( Luan.first( fn.call(luan,new Object[]{this}) ) );
 	}
 
 	public String rawToString() {
 		return "table: " + Integer.toHexString(hashCode());
 	}
 
-	public Object get(LuanBit bit,Object key) throws LuanException {
+	public Object get(LuanState luan,Object key) throws LuanException {
 		Object value = rawGet(key);
 		if( value != null )
 			return value;
@@ -117,26 +112,13 @@
 			return null;
 		if( h instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)h;
-			return Luan.first(bit.call(fn,"__index",new Object[]{this,key}));
+			return Luan.first(fn.call(luan,new Object[]{this,key}));
 		}
 		if( h instanceof LuanMeta ) {
 			LuanMeta meta = (LuanMeta)h;
-			return meta.__index(bit.luan,this,key);
+			return meta.__index(luan,this,key);
 		}
-		return index(bit,h,key);
-	}
-
-	public static Object index(LuanBit bit,Object obj,Object key) throws LuanException {
-		if( obj instanceof LuanTable ) {
-			LuanTable tbl = (LuanTable)obj;
-			return tbl.get(bit,key);
-		}
-		if( obj != null && bit.luan.hasJava() )
-			return JavaLuan.__index(bit,obj,key,false);
-		else if( bit.el==null )
-			throw bit.exception( "attempt to index a " + Luan.type(obj) + " value" );
-		else
-			throw bit.exception( "attempt to index a " + Luan.type(obj) + " value in '"+bit.el.text()+"'" );
+		return luan.index(h,key);
 	}
 
 	public Object rawGet(Object key) {
@@ -157,7 +139,7 @@
 		return map.get(key);
 	}
 
-	public void put(LuanBit bit,Object key,Object value) throws LuanException {
+	public void put(LuanState luan,Object key,Object value) throws LuanException {
 		Object h = getHandler("__new_index");
 		if( h==null || rawGet(key)!=null ) {
 			rawPut(key,value);
@@ -165,20 +147,20 @@
 		}
 		if( h instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)h;
-			bit.call(fn,"__new_index",new Object[]{this,key,value});
+			fn.call(luan,new Object[]{this,key,value});
 			return;
 		}
 		if( h instanceof LuanMeta ) {
 			LuanMeta meta = (LuanMeta)h;
-			meta.__new_index(bit.luan,this,key,value);
+			meta.__new_index(luan,this,key,value);
 			return;
 		}
 		if( h instanceof LuanTable ) {
 			LuanTable tbl = (LuanTable)h;
-			tbl.put(bit,key,value);
+			tbl.put(luan,key,value);
 			return;
 		}
-		throw bit.exception("invalid type "+Luan.type(h)+" for metamethod __new_index");
+		throw luan.exception("invalid type "+Luan.type(h)+" for metamethod __new_index");
 	}
 
 	public void rawPut(Object key,Object val) {
@@ -262,11 +244,11 @@
 		Collections.sort(list(),cmp);
 	}
 
-	public int length(LuanBit bit) throws LuanException {
+	public int length(LuanState luan) throws LuanException {
 		Object h = getHandler("__len");
 		if( h != null ) {
-			LuanFunction fn = bit.checkFunction(h);
-			return (Integer)Luan.first(bit.call(fn,"__len",new Object[]{this}));
+			LuanFunction fn = luan.checkFunction(h);
+			return (Integer)Luan.first(fn.call(luan,new Object[]{this}));
 		}
 		return rawLength();
 	}
@@ -275,8 +257,8 @@
 		return list==null ? 0 : list.size();
 	}
 
-	public Iterable<Map.Entry<Object,Object>> iterable(LuanBit bit) throws LuanException {
-		final Iterator<Map.Entry<Object,Object>> iter = iterator(bit);
+	public Iterable<Map.Entry<Object,Object>> iterable(LuanState luan) throws LuanException {
+		final Iterator<Map.Entry<Object,Object>> iter = iterator(luan);
 		return new Iterable<Map.Entry<Object,Object>>() {
 			public Iterator<Map.Entry<Object,Object>> iterator() {
 				return iter;
@@ -293,16 +275,16 @@
 		};
 	}
 
-	public Iterator<Map.Entry<Object,Object>> iterator(final LuanBit bit) throws LuanException {
+	public Iterator<Map.Entry<Object,Object>> iterator(final LuanState luan) throws LuanException {
 		if( getHandler("__pairs") == null )
 			return rawIterator();
-		final LuanFunction fn = pairs(bit);
+		final LuanFunction fn = pairs(luan);
 		return new Iterator<Map.Entry<Object,Object>>() {
 			private Map.Entry<Object,Object> next = getNext();
 
 			private Map.Entry<Object,Object> getNext() {
 				try {
-					Object obj = bit.call(fn,null,LuanFunction.NOTHING);
+					Object obj = fn.call(luan);
 					if( obj==null )
 						return null;
 					Object[] a = (Object[])obj;
@@ -330,20 +312,21 @@
 		};
 	}
 
-	public LuanFunction pairs(LuanBit bit) throws LuanException {
+	public LuanFunction pairs(LuanState luan) throws LuanException {
 		Object h = getHandler("__pairs");
 		if( h != null ) {
 			if( h instanceof LuanFunction ) {
-				Object obj = Luan.first(bit.call((LuanFunction)h,"__pairs",new Object[]{this}));
+				LuanFunction fn = (LuanFunction)h;
+				Object obj = Luan.first(fn.call(luan,new Object[]{this}));
 				if( !(obj instanceof LuanFunction) )
-					throw bit.exception( "metamethod __pairs should return function but returned " + Luan.type(obj) );
+					throw luan.exception( "metamethod __pairs should return function but returned " + Luan.type(obj) );
 				return (LuanFunction)obj;
 			}
 			if( h instanceof LuanMeta ) {
 				LuanMeta meta = (LuanMeta)h;
-				return meta.__pairs(bit.luan,this);
+				return meta.__pairs(luan,this);
 			}
-			throw bit.exception( "invalid type of metamethod __pairs: " + Luan.type(h) );
+			throw luan.exception( "invalid type of metamethod __pairs: " + Luan.type(h) );
 		}
 		return rawPairs();
 	}
@@ -436,25 +419,25 @@
 		return new LinkedHashMap<Object,Object>();
 	}
 
-	public boolean isSet(LuanBit bit) throws LuanException {
-		for( Map.Entry<Object,Object> entry : iterable(bit) ) {
+	public boolean isSet(LuanState luan) throws LuanException {
+		for( Map.Entry<Object,Object> entry : iterable(luan) ) {
 			if( !entry.getValue().equals(Boolean.TRUE) )
 				return false;
 		}
 		return true;
 	}
 
-	public Set<Object> asSet(LuanBit bit) throws LuanException {
+	public Set<Object> asSet(LuanState luan) throws LuanException {
 		Set<Object> set = new HashSet<Object>();
-		for( Map.Entry<Object,Object> entry : iterable(bit) ) {
+		for( Map.Entry<Object,Object> entry : iterable(luan) ) {
 			set.add(entry.getKey());
 		}
 		return set;
 	}
 
-	public Map<Object,Object> asMap(LuanBit bit) throws LuanException {
+	public Map<Object,Object> asMap(LuanState luan) throws LuanException {
 		Map<Object,Object> map = newMap();
-		for( Map.Entry<Object,Object> entry : iterable(bit) ) {
+		for( Map.Entry<Object,Object> entry : iterable(luan) ) {
 			map.put(entry.getKey(),entry.getValue());
 		}
 		return map;