Mercurial Hosting > luan
view src/luan/impl/Closure.java @ 1316:11d3640e739d
load_file returns nil for missing file
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Jan 2019 04:26:23 -0700 |
parents | 3ef883468fd0 |
children |
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.LuanJavaOk; public abstract class Closure extends LuanFunction implements LuanCloneable, Cloneable { protected Pointer[] upValues; protected LuanJavaOk javaOk; private LuanCloner cloner; public Closure(int nUpValues,LuanJavaOk javaOk) throws LuanException { this.upValues = new Pointer[nUpValues]; this.javaOk = javaOk; } @Override public Closure shallowClone() { check(); try { return (Closure)clone(); } catch(CloneNotSupportedException e) { throw new RuntimeException(e); } } @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) { Closure clone = (Closure)dc; switch( cloner.type ) { case COMPLETE: clone.upValues = (Pointer[])cloner.clone(upValues); clone.javaOk = (LuanJavaOk)cloner.clone(javaOk); return; case INCREMENTAL: clone.cloner = cloner; clone.upValues = upValues; clone.javaOk = javaOk; return; } } private void check() { if( cloner != null ) { upValues = (Pointer[])cloner.clone(upValues); javaOk = (LuanJavaOk)cloner.clone(javaOk); cloner = null; } } @Override public final Object call(LuanState luan,Object[] args) throws LuanException { if( luan.isLocked ) throw new RuntimeException("luan is locked"); check(); LuanJavaOk old = luan.javaOk; luan.javaOk = javaOk; try { return doCall(luan,args); } catch(StackOverflowError e) { throw new LuanException( "stack overflow" ); } finally { luan.javaOk = old; } } public abstract Object doCall(LuanState luan,Object[] args) throws LuanException; }