Mercurial Hosting > luan
comparison src/luan/interp/IndexExpr.java @ 3:7a2cdbc5767f
add LuaState
git-svn-id: https://luan-java.googlecode.com/svn/trunk@4 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 16 Nov 2012 05:23:12 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:4da26b11d12a | 3:7a2cdbc5767f |
---|---|
1 package luan.interp; | |
2 | |
3 import luan.Lua; | |
4 import luan.LuaException; | |
5 import luan.LuaState; | |
6 import luan.LuaTable; | |
7 | |
8 | |
9 final class IndexExpr extends BinaryOpExpr { | |
10 | |
11 IndexExpr(Expr op1,Expr op2) { | |
12 super(op1,op2); | |
13 } | |
14 | |
15 @Override Object eval(LuaState lua) throws LuaException { | |
16 Object t = op1.eval(lua); | |
17 if( t instanceof LuaTable ) { | |
18 LuaTable tbl = (LuaTable)t; | |
19 Object key = op2.eval(lua); | |
20 return tbl.get(key); | |
21 } | |
22 throw new LuaException( "attempt to index a " + Lua.type(t) + " value" ); | |
23 } | |
24 } |