view core/src/luan/impl/Closure.java @ 739:f8a7cc1fd3f6

remove Io.my_ips() not needed
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Jul 2016 17:47:12 -0600
parents f1c935be546d
children
line wrap: on
line source

package luan.impl;

import luan.Luan;
import luan.LuanFunction;
import luan.LuanState;
import luan.LuanException;
import luan.DeepCloner;
import luan.DeepCloneable;
import luan.LuanJava;


public abstract class Closure extends LuanFunction implements DeepCloneable, 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(DeepCloneable dc,DeepCloner 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;
}