diff core/src/luan/LuanState.java @ 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
line wrap: on
line diff
--- 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();
+	}
 }