diff src/luan/interp/UpValue.java @ 77:4bf3d0c0b6b9

make LuanState cloneable git-svn-id: https://luan-java.googlecode.com/svn/trunk@78 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 15 Feb 2013 09:55:17 +0000
parents f86e4f77ef32
children 7c08b611125d
line wrap: on
line diff
--- a/src/luan/interp/UpValue.java	Fri Feb 15 04:52:16 2013 +0000
+++ b/src/luan/interp/UpValue.java	Fri Feb 15 09:55:17 2013 +0000
@@ -1,7 +1,10 @@
 package luan.interp;
 
+import luan.DeepCloner;
+import luan.DeepCloneable;
 
-final class UpValue {
+
+final class UpValue implements DeepCloneable<UpValue> {
 	private Object[] stack;
 	private int index;
 	private boolean isClosed = false;
@@ -17,6 +20,23 @@
 		this.isClosed = true;
 	}
 
+	private UpValue() {}
+
+	@Override public UpValue shallowClone() {
+		return new UpValue();
+	}
+
+	@Override public void deepenClone(UpValue clone,DeepCloner cloner) {
+		clone.isClosed = isClosed;
+		if( isClosed ) {
+			clone.value = cloner.get(value);
+		} else {
+			clone.stack = stack.clone();
+			cloner.deepenClone(clone.stack);
+			clone.index = index;
+		}
+	}
+
 	Object get() {
 		return isClosed ? value : stack[index];
 	}
@@ -65,7 +85,7 @@
 
 	static final Getter globalGetter = new Getter() {
 		public UpValue get(LuanStateImpl luan) {
-			return new UpValue(luan.global);
+			return new UpValue(luan.global());
 		}
 	};