Mercurial Hosting > luan
comparison src/luan/interp/Closure.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 | 8ede219cd111 |
children | 7c08b611125d |
comparison
equal
deleted
inserted
replaced
76:97b03fc807ad | 77:4bf3d0c0b6b9 |
---|---|
2 | 2 |
3 import luan.LuanFunction; | 3 import luan.LuanFunction; |
4 import luan.LuanState; | 4 import luan.LuanState; |
5 import luan.LuanElement; | 5 import luan.LuanElement; |
6 import luan.LuanException; | 6 import luan.LuanException; |
7 import luan.DeepCloner; | |
8 import luan.DeepCloneable; | |
7 | 9 |
8 | 10 |
9 final class Closure extends LuanFunction { | 11 final class Closure extends LuanFunction implements DeepCloneable<Closure> { |
10 private final Chunk chunk; | 12 private final Chunk chunk; |
11 final UpValue[] upValues; | 13 final UpValue[] upValues; |
12 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; | 14 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; |
13 | 15 |
14 Closure(LuanStateImpl luan,Chunk chunk) { | 16 Closure(LuanStateImpl luan,Chunk chunk) { |
20 upValues = new UpValue[upValueGetters.length]; | 22 upValues = new UpValue[upValueGetters.length]; |
21 for( int i=0; i<upValues.length; i++ ) { | 23 for( int i=0; i<upValues.length; i++ ) { |
22 upValues[i] = upValueGetters[i].get(luan); | 24 upValues[i] = upValueGetters[i].get(luan); |
23 } | 25 } |
24 } | 26 } |
27 } | |
28 | |
29 private Closure(Closure c) { | |
30 this.chunk = c.chunk; | |
31 this.upValues = c.upValues==NO_UP_VALUES ? NO_UP_VALUES : c.upValues.clone(); | |
32 } | |
33 | |
34 @Override public Closure shallowClone() { | |
35 return new Closure(this); | |
36 } | |
37 | |
38 @Override public void deepenClone(Closure clone,DeepCloner cloner) { | |
39 cloner.deepenClone(clone.upValues); | |
25 } | 40 } |
26 | 41 |
27 public Object[] call(LuanState luan,Object[] args) throws LuanException { | 42 public Object[] call(LuanState luan,Object[] args) throws LuanException { |
28 return call(this,(LuanStateImpl)luan,args); | 43 return call(this,(LuanStateImpl)luan,args); |
29 } | 44 } |