Mercurial Hosting > luan
comparison core/src/luan/impl/Closure.java @ 672:d3e5414bdf4c
better java permission handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Apr 2016 17:03:30 -0600 |
parents | 58ebfec6178b |
children | f1c935be546d |
comparison
equal
deleted
inserted
replaced
671:82f130eba7b0 | 672:d3e5414bdf4c |
---|---|
4 import luan.LuanFunction; | 4 import luan.LuanFunction; |
5 import luan.LuanState; | 5 import luan.LuanState; |
6 import luan.LuanException; | 6 import luan.LuanException; |
7 import luan.DeepCloner; | 7 import luan.DeepCloner; |
8 import luan.DeepCloneable; | 8 import luan.DeepCloneable; |
9 import luan.LuanJava; | |
9 | 10 |
10 | 11 |
11 public abstract class Closure extends LuanFunction implements DeepCloneable, Cloneable { | 12 public abstract class Closure extends LuanFunction implements DeepCloneable, Cloneable { |
12 public Pointer[] upValues; | 13 public Pointer[] upValues; |
14 public LuanJava java; | |
13 | 15 |
14 public Closure(int nUpValues) throws LuanException { | 16 public Closure(int nUpValues,LuanJava java) throws LuanException { |
15 this.upValues = new Pointer[nUpValues]; | 17 this.upValues = new Pointer[nUpValues]; |
18 this.java = java; | |
16 } | 19 } |
17 | 20 |
18 @Override public Closure shallowClone() { | 21 @Override public Closure shallowClone() { |
19 try { | 22 try { |
20 return (Closure)clone(); | 23 return (Closure)clone(); |
21 } catch(CloneNotSupportedException e) { | 24 } catch(CloneNotSupportedException e) { |
22 throw new RuntimeException(e); | 25 throw new RuntimeException(e); |
23 } | 26 } |
24 } | 27 } |
25 | 28 |
26 @Override public void deepenClone(DeepCloneable clone,DeepCloner cloner) { | 29 @Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) { |
27 ((Closure)clone).upValues = (Pointer[])cloner.deepClone(upValues); | 30 Closure clone = (Closure)dc; |
31 clone.upValues = (Pointer[])cloner.deepClone(upValues); | |
32 clone.java = (LuanJava)cloner.deepClone(java); | |
28 } | 33 } |
29 | 34 |
30 @Override public final Object call(LuanState ls,Object[] args) throws LuanException { | 35 @Override public final Object call(LuanState luan,Object[] args) throws LuanException { |
31 LuanStateImpl luan = (LuanStateImpl)ls; | 36 LuanJava old = luan.java; |
32 Closure old = luan.closure; | 37 luan.java = java; |
33 luan.closure = this; | |
34 try { | 38 try { |
35 return doCall(luan,args); | 39 return doCall(luan,args); |
36 } finally { | 40 } finally { |
37 luan.closure = old; | 41 luan.java = old; |
38 } | 42 } |
39 } | 43 } |
40 | 44 |
41 public abstract Object doCall(LuanState luan,Object[] args) throws LuanException; | 45 public abstract Object doCall(LuanState luan,Object[] args) throws LuanException; |
42 } | 46 } |