diff core/src/luan/LuanState.java @ 672:d3e5414bdf4c

better java permission handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Apr 2016 17:03:30 -0600
parents 8e8c30b72e9b
children b620b8e1010f
line wrap: on
line diff
--- a/core/src/luan/LuanState.java	Tue Apr 12 14:44:10 2016 -0600
+++ b/core/src/luan/LuanState.java	Tue Apr 12 17:03:30 2016 -0600
@@ -13,23 +13,28 @@
 import luan.modules.JavaLuan;
 
 
-public abstract class LuanState implements DeepCloneable {
+public final class LuanState implements DeepCloneable {
 
+	public LuanJava java;
 	private Map registry;
 	private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
 
-	protected LuanState() {
+	public LuanState() {
+		java = new LuanJava();
 		registry = new HashMap();
 	}
 
-	protected LuanState(LuanState luan) {}
+	private LuanState(LuanState luan) {}
 
-	@Override public void deepenClone(DeepCloneable clone,DeepCloner cloner) {
-		((LuanState)clone).registry = cloner.deepClone(registry);
+	@Override public LuanState shallowClone() {
+		return new LuanState(this);
 	}
 
-	public abstract boolean hasJava();
-	public abstract void setJava();
+	@Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
+		LuanState clone = (LuanState)dc;
+		clone.registry = cloner.deepClone(registry);
+		clone.java = (LuanJava)cloner.deepClone(java);
+	}
 
 	public final Map registry() {
 		return registry;
@@ -48,10 +53,6 @@
 		onClose.clear();
 	}
 
-	public static LuanState newInstance() {
-		return LuanCompiler.newLuanState();
-	}
-
 	public final Object eval(String cmd) throws LuanException {
 		return eval(cmd,new LuanTable());
 	}
@@ -81,7 +82,7 @@
 			LuanTable tbl = (LuanTable)obj;
 			return tbl.get(this,key);
 		}
-		if( obj != null && hasJava() )
+		if( obj != null && java.ok )
 			return JavaLuan.__index(this,obj,key,false);
 		throw new LuanException("attempt to index a " + Luan.type(obj) + " value" );
 	}