view src/luan/interp/Block.java @ 23:2446c1755d9b

minor git-svn-id: https://luan-java.googlecode.com/svn/trunk@24 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 06 Dec 2012 00:35:13 +0000
parents c93d8c781853
children 5cf15507d77e
line wrap: on
line source

package luan.interp;

import luan.LuaState;
import luan.LuaException;


final class Block implements Stmt {
	final Stmt[] stmts;
	private final int stackStart;
	private final int stackEnd;

	Block(Stmt[] stmts,int stackStart,int stackEnd) {
		if( stmts.length==0 )
			throw new RuntimeException("empty block");
		this.stmts = stmts;
		this.stackStart = stackStart;
		this.stackEnd = stackEnd;
	}

	@Override public void eval(LuaState lua) throws LuaException {
		try {
			for( Stmt stmt : stmts ) {
				stmt.eval(lua);
			}
		} finally {
			Object[] stack = lua.stack();
			for( int i=stackStart; i<stackEnd; i++ ) {
				stack[i] = null;
			}
		}
	}

}