Mercurial Hosting > luan
view src/luan/impl/Closure.java @ 781:fbbdd369a13a
rename DeepCloner to LuanCloner
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 29 Aug 2016 22:49:32 -0600 |
parents | 1a68fc55a80c |
children | 655280eab1e2 |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanFunction; import luan.LuanState; import luan.LuanException; import luan.LuanCloner; import luan.LuanCloneable; import luan.LuanJava; public abstract class Closure extends LuanFunction implements LuanCloneable, Cloneable { public Pointer[] upValues; public LuanJava java; public Closure(int nUpValues,LuanJava java) throws LuanException { this.upValues = new Pointer[nUpValues]; this.java = java; } @Override public Closure shallowClone() { try { return (Closure)clone(); } catch(CloneNotSupportedException e) { throw new RuntimeException(e); } } @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) { Closure clone = (Closure)dc; clone.upValues = (Pointer[])cloner.deepClone(upValues); clone.java = (LuanJava)cloner.deepClone(java); } @Override public final Object call(LuanState luan,Object[] args) throws LuanException { LuanJava old = luan.java; luan.java = java; try { return doCall(luan,args); } catch(StackOverflowError e) { throw new LuanException( "stack overflow" ); } finally { luan.java = old; } } public abstract Object doCall(LuanState luan,Object[] args) throws LuanException; }