view src/luan/interp/SetTableEntry.java @ 31:5cf15507d77e

separate interpreter from interface git-svn-id: https://luan-java.googlecode.com/svn/trunk@32 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 13 Dec 2012 02:50:04 +0000
parents 09d41f7490a8
children e51906de0f11
line wrap: on
line source

package luan.interp;

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


final class SetTableEntry implements Settable {
	private final Expr tableExpr;
	private final Expr keyExpr;

	SetTableEntry(Expr tableExpr,Expr keyExpr) {
		this.tableExpr = tableExpr;
		this.keyExpr = keyExpr;
	}

	@Override public void set(LuaStateImpl lua,Object value) throws LuaException {
		Object t = tableExpr.eval(lua);
		if( !(t instanceof LuaTable) )
			throw new LuaException( "attempt to index a " + Lua.type(t) + " value" );
		LuaTable table = (LuaTable)t;
		Object key = keyExpr.eval(lua);
		table.set(key,value);
	}

}