view src/luan/interp/GetExpr.java @ 11:b7d7069fee58

add assignment statement and CmdLine git-svn-id: https://luan-java.googlecode.com/svn/trunk@12 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 22 Nov 2012 10:51:56 +0000
parents 24fd6381caca
children 5cf15507d77e
line wrap: on
line source

package luan.interp;

import luan.Lua;
import luan.LuaException;
import luan.LuaState;
import luan.LuaTable;


final class GetExpr extends BinaryOpExpr {

	GetExpr(Expr op1,Expr op2) {
		super(op1,op2);
	}

	@Override public Object eval(LuaState lua) throws LuaException {
		Object t = op1.eval(lua);
		if( t instanceof LuaTable ) {
			LuaTable tbl = (LuaTable)t;
			Object key = op2.eval(lua);
			return tbl.get(key);
		}
		throw new LuaException( "attempt to index a " + Lua.type(t) + " value" );
	}
}