changeset 575:7c3ad6db8ac3

make LuanState.JAVA private
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 13 Jul 2015 18:34:31 -0600
parents 6cc2f047019b
children 4723d22062ce
files core/src/luan/LuanBit.java core/src/luan/LuanException.java core/src/luan/LuanJavaFunction.java core/src/luan/LuanState.java core/src/luan/LuanTable.java core/src/luan/impl/IndexExpr.java core/src/luan/impl/LenExpr.java core/src/luan/impl/SetTableEntry.java core/src/luan/modules/BasicLuan.java core/src/luan/modules/HtmlLuan.java core/src/luan/modules/IoLuan.java core/src/luan/modules/JavaLuan.java core/src/luan/modules/PackageLuan.java core/src/luan/modules/PickleCon.java core/src/luan/modules/StringLuan.java core/src/luan/modules/TableLuan.java logging/src/luan/modules/logging/LuanLogger.java lucene/src/luan/modules/lucene/LuceneIndex.java mail/src/luan/modules/mail/SmtpCon.java
diffstat 19 files changed, 160 insertions(+), 131 deletions(-) [+]
line wrap: on
line diff
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/LuanBit.java
--- a/core/src/luan/LuanBit.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/LuanBit.java	Mon Jul 13 18:34:31 2015 -0600
@@ -41,17 +41,53 @@
 		}
 	}
 
-	public void push(String fnName) {
+	private void push(String fnName) {
 		if( el == null )  throw new RuntimeException();
 		List<StackTraceElement> stackTrace = luan.stackTrace;
 		stackTrace.add( new StackTraceElement(el,fnName) );
 	}
 
-	public void pop() {
+	private void pop() {
 		List<StackTraceElement> stackTrace = luan.stackTrace;
 		stackTrace.remove(stackTrace.size()-1);
 	}
 
+	public String toString(Object obj) throws LuanException {
+		push(null);
+		try {
+			return luan.toString(obj);
+		} finally {
+			pop();
+		}
+	}
+
+	public Object index(Object obj,Object key) throws LuanException {
+		push(null);
+		try {
+			return luan.index(obj,key);
+		} finally {
+			pop();
+		}
+	}
+
+	public int length(LuanTable t) throws LuanException {
+		push(null);
+		try {
+			return t.length(luan);
+		} finally {
+			pop();
+		}
+	}
+
+	public void put(LuanTable t,Object key,Object value) throws LuanException {
+		push(null);
+		try {
+			t.put(luan,key,value);
+		} finally {
+			pop();
+		}
+	}
+
 	public String checkString(Object obj) throws LuanException {
 		if( obj instanceof String )
 			return (String)obj;
@@ -133,18 +169,4 @@
 		throw exception("attempt to perform arithmetic on a "+type+" value");
 	}
 
-	public String toString(Object obj) throws LuanException {
-		if( obj instanceof LuanTable ) {
-			LuanTable tbl = (LuanTable)obj;
-			return tbl.toString(this);
-		}
-		if( obj == null )
-			return "nil";
-		if( obj instanceof Number )
-			return Luan.toString((Number)obj);
-		if( obj instanceof byte[] )
-			return "binary: " + Integer.toHexString(obj.hashCode());
-		return obj.toString();
-	}
-
 }
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/LuanException.java
--- a/core/src/luan/LuanException.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/LuanException.java	Mon Jul 13 18:34:31 2015 -0600
@@ -12,10 +12,10 @@
 	}
 
 	LuanException(LuanBit bit,Object msg) throws LuanException {
-		this( bit.toString(msg), msg instanceof Throwable ? (Throwable)msg : null );
+		this( bit.luan.toString(msg), msg instanceof Throwable ? (Throwable)msg : null );
 		table.rawPut( "java", this );
 		table.rawPut( "message", msg );
-		table.rawPut( "message_string", bit.toString(msg) );
+		table.rawPut( "message_string", bit.luan.toString(msg) );
 		for( StackTraceElement ste : bit.stackTrace() ) {
 			LuanTable tbl = new LuanTable();
 			tbl.rawPut( "source", ste.call.source.name );
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/LuanJavaFunction.java
--- a/core/src/luan/LuanJavaFunction.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/LuanJavaFunction.java	Mon Jul 13 18:34:31 2015 -0600
@@ -383,7 +383,7 @@
 		public Object convert(LuanState luan,Object obj) throws LuanException {
 			if( obj instanceof LuanTable ) {
 				LuanTable t = (LuanTable)obj;
-				return t.asMap(luan.JAVA);
+				return t.asMap(luan);
 			}
 			return obj;
 		}
@@ -410,8 +410,8 @@
 		public Object convert(LuanState luan,Object obj) throws LuanException {
 			if( obj instanceof LuanTable ) {
 				LuanTable t = (LuanTable)obj;
-				if( t.isSet(luan.JAVA) )
-					return t.asSet(luan.JAVA);
+				if( t.isSet(luan) )
+					return t.asSet(luan);
 			}
 			return obj;
 		}
@@ -426,8 +426,8 @@
 				LuanTable t = (LuanTable)obj;
 				if( t.isList() )
 					return t.asList();
-				if( t.isSet(luan.JAVA) )
-					return t.asSet(luan.JAVA);
+				if( t.isSet(luan) )
+					return t.asSet(luan);
 			}
 			return obj;
 		}
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/LuanState.java
--- a/core/src/luan/LuanState.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/LuanState.java	Mon Jul 13 18:34:31 2015 -0600
@@ -10,6 +10,7 @@
 import java.util.HashMap;
 import luan.impl.LuanCompiler;
 import luan.modules.BasicLuan;
+import luan.modules.JavaLuan;
 
 
 public abstract class LuanState implements DeepCloneable {
@@ -69,7 +70,7 @@
 
 	// convenience methods
 
-	public final LuanBit JAVA = bit(null);
+	private final LuanBit JAVA = bit(null);
 
 	public LuanException exception(Object msg) throws LuanException {
 		return JAVA.exception(msg);
@@ -90,4 +91,32 @@
 	public boolean isLessThan(Object o1,Object o2) throws LuanException {
 		return JAVA.isLessThan(o1,o2);
 	}
+
+	public String toString(Object obj) throws LuanException {
+		if( obj instanceof LuanTable ) {
+			LuanTable tbl = (LuanTable)obj;
+			return tbl.toString(this);
+		}
+		if( obj == null )
+			return "nil";
+		if( obj instanceof Number )
+			return Luan.toString((Number)obj);
+		if( obj instanceof byte[] )
+			return "binary: " + Integer.toHexString(obj.hashCode());
+		return obj.toString();
+	}
+
+	public Object index(Object obj,Object key) throws LuanException {
+		if( obj instanceof LuanTable ) {
+			LuanTable tbl = (LuanTable)obj;
+			return tbl.get(this,key);
+		}
+		if( obj != null && hasJava() )
+			return JavaLuan.__index(this,obj,key,false);
+		throw exception( "attempt to index a " + Luan.type(obj) + " value in '"+context()+"'" );
+	}
+
+	public String context() {
+		return stackTrace.get(stackTrace.size()-1).call.text();
+	}
 }
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/LuanTable.java
--- 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;
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/impl/IndexExpr.java
--- a/core/src/luan/impl/IndexExpr.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/impl/IndexExpr.java	Mon Jul 13 18:34:31 2015 -0600
@@ -1,7 +1,6 @@
 package luan.impl;
 
 import luan.LuanException;
-import luan.LuanTable;
 import luan.LuanElement;
 
 
@@ -12,7 +11,7 @@
 	}
 
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
-		return LuanTable.index( luan.bit(el()), op1.eval(luan), op2.eval(luan) );
+		return luan.bit(el()).index( op1.eval(luan), op2.eval(luan) );
 	}
 
 }
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/impl/LenExpr.java
--- a/core/src/luan/impl/LenExpr.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/impl/LenExpr.java	Mon Jul 13 18:34:31 2015 -0600
@@ -28,6 +28,6 @@
 		if( !(o instanceof LuanTable) )
 			throw bit.exception( "attempt to get length of a " + Luan.type(o) + " value" );
 		LuanTable t = (LuanTable)o;
-		return t.length(bit);
+		return bit.length(t);
 	}
 }
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/impl/SetTableEntry.java
--- a/core/src/luan/impl/SetTableEntry.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/impl/SetTableEntry.java	Mon Jul 13 18:34:31 2015 -0600
@@ -28,7 +28,7 @@
 		LuanBit bit = luan.bit(el());
 		if( t instanceof LuanTable ) {
 			LuanTable tbl = (LuanTable)t;
-			tbl.put(bit,key,value);
+			bit.put(tbl,key,value);
 			return;
 		}
 		if( t != null && luan.hasJava() )
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/BasicLuan.java
--- a/core/src/luan/modules/BasicLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -45,7 +45,7 @@
 
 	public static LuanFunction pairs(final LuanState luan,final LuanTable t) throws LuanException {
 		Utils.checkNotNull(luan,t);
-		return t.pairs(luan.JAVA);
+		return t.pairs(luan);
 	}
 
 	public static LuanFunction ipairs(LuanState luan,final LuanTable t) throws LuanException {
@@ -105,7 +105,7 @@
 	}
 
 	public static String to_string(LuanState luan,Object v) throws LuanException {
-		return luan.JAVA.toString(v);
+		return luan.toString(v);
 	}
 
 	public static LuanTable new_error(LuanState luan,Object msg) throws LuanException {
@@ -183,21 +183,21 @@
 
 	public static Object try_(LuanState luan,LuanTable blocks) throws LuanException {
 		Utils.checkNotNull(luan,blocks);
-		Object obj = blocks.get(luan.JAVA,1);
+		Object obj = blocks.get(luan,1);
 		if( obj == null )
 			throw luan.exception("missing 'try' value");
 		if( !(obj instanceof LuanFunction) )
 			throw luan.exception("bad 'try' value (function expected, got "+Luan.type(obj)+")");
 		LuanFunction tryFn = (LuanFunction)obj;
 		LuanFunction catchFn = null;
-		obj = blocks.get(luan.JAVA,"catch");
+		obj = blocks.get(luan,"catch");
 		if( obj != null ) {
 			if( !(obj instanceof LuanFunction) )
 				throw luan.exception("bad 'catch' value (function expected, got "+Luan.type(obj)+")");
 			catchFn = (LuanFunction)obj;
 		}
 		LuanFunction finallyFn = null;
-		obj = blocks.get(luan.JAVA,"finally");
+		obj = blocks.get(luan,"finally");
 		if( obj != null ) {
 			if( !(obj instanceof LuanFunction) )
 				throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")");
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/HtmlLuan.java
--- a/core/src/luan/modules/HtmlLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/HtmlLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -282,20 +282,20 @@
 				buf.append( o );
 			} else if( o instanceof LuanTable ) {
 				LuanTable t = (LuanTable)o;
-				String type = (String)t.get(luan.JAVA,"type");
+				String type = (String)t.get(luan,"type");
 				if( type==null )
 					throw luan.exception( "no type in element of table for 'Html.to_string'" );
 				if( type.equals("comment") ) {
-					buf.append( "<!--" ).append( t.get(luan.JAVA,"text") ).append( "-->" );
+					buf.append( "<!--" ).append( t.get(luan,"text") ).append( "-->" );
 				} else if( type.equals("cdata") ) {
-					buf.append( "<![CDATA[" ).append( t.get(luan.JAVA,"text") ).append( "]]" );
+					buf.append( "<![CDATA[" ).append( t.get(luan,"text") ).append( "]]" );
 				} else if( type.equals("tag") ) {
 					buf.append( tagToString(luan,t) );
 				} else if( type.equals("container") ) {
-					LuanTable tag  = (LuanTable)t.get(luan.JAVA,"tag");
+					LuanTable tag  = (LuanTable)t.get(luan,"tag");
 					buf.append( tagToString(luan,tag) );
-					buf.append( t.get(luan.JAVA,"text") );
-					buf.append( "</" ).append( tag.get(luan.JAVA,"name") ).append( ">" );
+					buf.append( t.get(luan,"text") );
+					buf.append( "</" ).append( tag.get(luan,"name") ).append( ">" );
 				} else {
 					throw luan.exception( "invalid element type for 'Html.to_string'" );
 				}
@@ -308,9 +308,9 @@
 	private static String tagToString(LuanState luan,LuanTable tbl) throws LuanException {
 		StringBuilder buf = new StringBuilder();
 		buf.append('<');
-		buf.append(tbl.get(luan.JAVA,"name"));
-		LuanTable attributes = (LuanTable)tbl.get(luan.JAVA,"attributes");
-		for( Map.Entry<Object,Object> attr : attributes.iterable(luan.JAVA) ) {
+		buf.append(tbl.get(luan,"name"));
+		LuanTable attributes = (LuanTable)tbl.get(luan,"attributes");
+		for( Map.Entry<Object,Object> attr : attributes.iterable(luan) ) {
 			buf.append( ' ' );
 			buf.append( attr.getKey() );
 			Object val = attr.getValue();
@@ -319,7 +319,7 @@
 				buf.append( quote((String)val) );
 			}
 		}
-		if( tbl.get(luan.JAVA,"is_empty").equals(Boolean.TRUE) )
+		if( tbl.get(luan,"is_empty").equals(Boolean.TRUE) )
 			buf.append('/');
 		buf.append('>');
 		return buf.toString();
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/IoLuan.java
--- a/core/src/luan/modules/IoLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/IoLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -58,7 +58,7 @@
 
 			public void write(LuanState luan,Object... args) throws LuanException {
 				for( Object obj : args ) {
-					out.print( luan.JAVA.toString(obj) );
+					out.print( luan.toString(obj) );
 				}
 			}
 
@@ -74,7 +74,7 @@
 
 			public void write(LuanState luan,Object... args) throws LuanException, IOException {
 				for( Object obj : args ) {
-					out.write( luan.JAVA.toString(obj) );
+					out.write( luan.toString(obj) );
 				}
 			}
 
@@ -339,7 +339,7 @@
 	
 				public void write(LuanState luan,Object... args) throws LuanException, IOException {
 					for( Object obj : args ) {
-						out.write( luan.JAVA.toString(obj) );
+						out.write( luan.toString(obj) );
 					}
 				}
 	
@@ -552,7 +552,7 @@
 
 	public static LuanTable stdin(LuanState luan) throws LuanException {
 		LuanTable io = (LuanTable)PackageLuan.require(luan,"luan:Io");
-		return (LuanTable)io.get(luan.JAVA,"stdin");
+		return (LuanTable)io.get(luan,"stdin");
 	}
 
 	public static LuanTable newSchemes() {
@@ -576,7 +576,7 @@
 		LuanTable t = (LuanTable)PackageLuan.loaded(luan).rawGet("luan:Io");
 		if( t == null )
 			return newSchemes();
-		t = (LuanTable)t.get(luan.JAVA,"schemes");
+		t = (LuanTable)t.get(luan,"schemes");
 		if( t == null )
 			return newSchemes();
 		return t;
@@ -589,7 +589,7 @@
 		String scheme = name.substring(0,i);
 		String location = name.substring(i+1);
 		LuanTable schemes = schemes(luan);
-		LuanFunction opener = (LuanFunction)schemes.get(luan.JAVA,scheme);
+		LuanFunction opener = (LuanFunction)schemes.get(luan,scheme);
 		if( opener == null )
 			throw luan.exception( "invalid scheme '"+scheme+"' in '"+name+"'" );
 		return (LuanTable)Luan.first(opener.call(luan,new Object[]{location,addExtension}));
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/JavaLuan.java
--- a/core/src/luan/modules/JavaLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/JavaLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -49,8 +49,7 @@
 
 	static final Object FAIL = new Object();
 
-	public static Object __index(LuanBit bit,Object obj,Object key,boolean canReturnFail) throws LuanException {
-		LuanState luan = bit.luan;
+	public static Object __index(LuanState luan,Object obj,Object key,boolean canReturnFail) throws LuanException {
 		checkJava(luan);
 		Class cls;
 		if( obj instanceof Static ) {
@@ -112,10 +111,7 @@
 //System.out.println("invalid member '"+key+"' for java object: "+obj);
 		if( canReturnFail )
 			return FAIL;
-		if( bit.el != null )
-			throw bit.exception( "invalid index for java "+cls+" in '"+bit.el.text()+"'" );
-		else
-			throw bit.exception( "invalid index for java "+cls );
+		throw luan.exception( "invalid index for java "+cls+" in '"+luan.context()+"'" );
 	}
 
 	private static Object member(Object obj,List<Member> members) throws LuanException {
@@ -331,7 +327,7 @@
 						if( args==null )
 							args = new Object[0];
 						String name = method.getName();
-						Object fnObj = t.get(luan.JAVA,name);
+						Object fnObj = t.get(luan,name);
 						if( fnObj == null )
 							throw new NullPointerException("luan_proxy couldn't find method '"+name+"'");
 						LuanFunction fn = luan.checkFunction(fnObj);
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/PackageLuan.java
--- a/core/src/luan/modules/PackageLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/PackageLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -69,11 +69,11 @@
 		LuanTable t = IoLuan.uri(luan,uri,addExtension);
 		if( t == null )
 			return null;
-		LuanFunction existsFn = (LuanFunction)t.get(luan.JAVA,"exists");
+		LuanFunction existsFn = (LuanFunction)t.get(luan,"exists");
 		boolean exists = (Boolean)Luan.first(existsFn.call(luan));
 		if( !exists )
 			return null;
-		LuanFunction reader = (LuanFunction)t.get(luan.JAVA,"read_text");
+		LuanFunction reader = (LuanFunction)t.get(luan,"read_text");
 		return (String)Luan.first(reader.call(luan));
 	}
 
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/PickleCon.java
--- a/core/src/luan/modules/PickleCon.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/PickleCon.java	Mon Jul 13 18:34:31 2015 -0600
@@ -96,7 +96,7 @@
 		}
 		StringBuilder sb = new StringBuilder();
 		sb.append( "{" );
-		for( Map.Entry<Object,Object> entry : tbl.iterable(luan.JAVA) ) {
+		for( Map.Entry<Object,Object> entry : tbl.iterable(luan) ) {
 			sb.append( "[" );
 			sb.append( pickle(entry.getKey(),set) );
 			sb.append( "]=" );
@@ -116,7 +116,7 @@
 			}
 		}
 		for( Object obj : args ) {
-			sb.append( luan.JAVA.toString(obj) );
+			sb.append( luan.toString(obj) );
 		}
 		writeString( sb.toString() );
 //System.out.println("aaaaaaaaaaaaaaaaaaaaaaaa");
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/StringLuan.java
--- a/core/src/luan/modules/StringLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -168,9 +168,9 @@
 			StringBuffer sb = new StringBuffer();
 			while( i<max && m.find() ) {
 				String match = m.groupCount()==0 ? m.group() : m.group(1);
-				Object val = t.get(luan.JAVA,match);
+				Object val = t.get(luan,match);
 				if( val != null ) {
-					String replacement = luan.JAVA.toString(val);
+					String replacement = luan.toString(val);
 					m.appendReplacement(sb,replacement);
 				}
 				i++;
@@ -195,7 +195,7 @@
 				}
 				Object val = Luan.first( fn.call(luan,args) );
 				if( val != null ) {
-					String replacement = luan.JAVA.toString(val);
+					String replacement = luan.toString(val);
 					m.appendReplacement(sb,replacement);
 				}
 				i++;
@@ -214,7 +214,7 @@
 	public static String concat(LuanState luan,Object... args) throws LuanException {
 		StringBuilder sb = new StringBuilder();
 		for( Object arg : args ) {
-			sb.append( luan.JAVA.toString(arg) );
+			sb.append( luan.toString(arg) );
 		}
 		return sb.toString();
 	}
diff -r 6cc2f047019b -r 7c3ad6db8ac3 core/src/luan/modules/TableLuan.java
--- a/core/src/luan/modules/TableLuan.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/core/src/luan/modules/TableLuan.java	Mon Jul 13 18:34:31 2015 -0600
@@ -18,15 +18,15 @@
 
 	public static String concat(LuanState luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException {
 		int first = i==null ? 1 : i;
-		int last = j==null ? list.length(luan.JAVA) : j;
+		int last = j==null ? list.length(luan) : j;
 		StringBuilder buf = new StringBuilder();
 		for( int k=first; k<=last; k++ ) {
-			Object val = list.get(luan.JAVA,k);
+			Object val = list.get(luan,k);
 			if( val==null )
 				break;
 			if( sep!=null && k > first )
 				buf.append(sep);
-			String s = luan.JAVA.toString(val);
+			String s = luan.toString(val);
 			buf.append(s);
 		}
 		return buf.toString();
@@ -92,10 +92,10 @@
 
 	@LuanMethod public static Object[] unpack(LuanState luan,LuanTable tbl,Integer iFrom,Integer iTo) throws LuanException {
 		int from = iFrom!=null ? iFrom : 1;
-		int to = iTo!=null ? iTo : tbl.length(luan.JAVA);
+		int to = iTo!=null ? iTo : tbl.length(luan);
 		List<Object> list = new ArrayList<Object>();
 		for( int i=from; i<=to; i++ ) {
-			list.add( tbl.get(luan.JAVA,i) );
+			list.add( tbl.get(luan,i) );
 		}
 		return list.toArray();
 	}
diff -r 6cc2f047019b -r 7c3ad6db8ac3 logging/src/luan/modules/logging/LuanLogger.java
--- a/logging/src/luan/modules/logging/LuanLogger.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/logging/src/luan/modules/logging/LuanLogger.java	Mon Jul 13 18:34:31 2015 -0600
@@ -16,19 +16,19 @@
 	}
 
 	public void error(LuanState luan,Object obj) throws LuanException {
-		logger.error( luan.JAVA.toString(obj) );
+		logger.error( luan.toString(obj) );
 	}
 
 	public void warn(LuanState luan,Object obj) throws LuanException {
-		logger.warn( luan.JAVA.toString(obj) );
+		logger.warn( luan.toString(obj) );
 	}
 
 	public void info(LuanState luan,Object obj) throws LuanException {
-		logger.info( luan.JAVA.toString(obj) );
+		logger.info( luan.toString(obj) );
 	}
 
 	public void debug(LuanState luan,Object obj) throws LuanException {
-		logger.debug( luan.JAVA.toString(obj) );
+		logger.debug( luan.toString(obj) );
 	}
 
 }
diff -r 6cc2f047019b -r 7c3ad6db8ac3 lucene/src/luan/modules/lucene/LuceneIndex.java
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jul 13 18:34:31 2015 -0600
@@ -134,16 +134,16 @@
 	}
 
 	public void save(LuanState luan,LuanTable doc) throws LuanException, IOException {
-		if( doc.get(luan.JAVA,"type")==null )
+		if( doc.get(luan,"type")==null )
 			throw luan.exception("missing 'type' field");
-		Long id = (Long)doc.get(luan.JAVA,"id");
+		Long id = (Long)doc.get(luan,"id");
 
 		boolean commit = !writeLock.isHeldByCurrentThread();
 		writeLock.lock();
 		try {
 			if( id == null ) {
 				id = nextId(luan);
-				doc.put(luan.JAVA,"id",id);
+				doc.put(luan,"id",id);
 				writer.addDocument(toLucene(luan,doc));
 			} else {
 				writer.updateDocument( term("id",id), toLucene(luan,doc) );
@@ -403,7 +403,7 @@
 	private Document toLucene(LuanState luan,LuanTable table) throws LuanException {
 		Set<String> indexed = mfp.fields.keySet();
 		Document doc = new Document();
-		for( Map.Entry<Object,Object> entry : table.iterable(luan.JAVA) ) {
+		for( Map.Entry<Object,Object> entry : table.iterable(luan) ) {
 			Object key = entry.getKey();
 			if( !(key instanceof String) )
 				throw luan.exception("key must be string");
diff -r 6cc2f047019b -r 7c3ad6db8ac3 mail/src/luan/modules/mail/SmtpCon.java
--- a/mail/src/luan/modules/mail/SmtpCon.java	Mon Jul 13 12:31:53 2015 -0600
+++ b/mail/src/luan/modules/mail/SmtpCon.java	Mon Jul 13 18:34:31 2015 -0600
@@ -25,7 +25,7 @@
 	private final Session session;
 
 	public SmtpCon(LuanState luan,LuanTable paramsTbl) throws LuanException {
-		Map<Object,Object> params = new HashMap<Object,Object>(paramsTbl.asMap(luan.JAVA));
+		Map<Object,Object> params = new HashMap<Object,Object>(paramsTbl.asMap(luan));
 		Properties props = new Properties(System.getProperties());
 
 		String host = getString(luan,params,"host");
@@ -81,7 +81,7 @@
 
 	public void send(LuanState luan,LuanTable mailTbl) throws LuanException {
 		try {
-			Map<Object,Object> mailParams = new HashMap<Object,Object>(mailTbl.asMap(luan.JAVA));
+			Map<Object,Object> mailParams = new HashMap<Object,Object>(mailTbl.asMap(luan));
 			MimeMessage msg = new MimeMessage(session);
 
 			String from = getString(luan,mailParams,"from");
@@ -109,7 +109,7 @@
 					bodyPart.setText((String)body);
 				} else if( body instanceof LuanTable ) {
 					LuanTable bodyTbl = (LuanTable)body;
-					Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap(luan.JAVA));
+					Map<Object,Object> map = new HashMap<Object,Object>(bodyTbl.asMap(luan));
 					MimeMultipart mp = new MimeMultipart("alternative");
 					String text = (String)map.remove("text");
 					if( text != null ) {
@@ -142,7 +142,7 @@
 				for( Object attachment : attachmentsTbl.asList() ) {
 					if( !(attachment instanceof LuanTable) )
 						throw luan.exception( "each attachment must be a table" );
-					Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap(luan.JAVA));
+					Map<Object,Object> attachmentMap = new HashMap<Object,Object>(((LuanTable)attachment).asMap(luan));
 					Object obj;
 
 					obj = attachmentMap.remove("filename");