diff src/luan/interp/SetTableEntry.java @ 17:09d41f7490a8

add local variables git-svn-id: https://luan-java.googlecode.com/svn/trunk@18 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 30 Nov 2012 11:46:34 +0000
parents
children 5cf15507d77e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/interp/SetTableEntry.java	Fri Nov 30 11:46:34 2012 +0000
@@ -0,0 +1,27 @@
+package luan.interp;
+
+import luan.LuaState;
+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(LuaState 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);
+	}
+
+}