Mercurial Hosting > luan
comparison src/luan/interp/TableExpr.java @ 25:0e406bd9ac7b
fix table constructors
git-svn-id: https://luan-java.googlecode.com/svn/trunk@26 21e917c8-12df-6dd8-5cb6-c86387c605b9
| author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
|---|---|
| date | Thu, 06 Dec 2012 09:36:24 +0000 |
| parents | b7d7069fee58 |
| children | 5cf15507d77e |
comparison
equal
deleted
inserted
replaced
| 24:7ee247560db5 | 25:0e406bd9ac7b |
|---|---|
| 1 package luan.interp; | 1 package luan.interp; |
| 2 | 2 |
| 3 import luan.LuaException; | 3 import luan.LuaException; |
| 4 import luan.LuaState; | 4 import luan.LuaState; |
| 5 import luan.LuaTable; | 5 import luan.LuaTable; |
| 6 import luan.LuaNumber; | |
| 6 | 7 |
| 7 | 8 |
| 8 final class TableExpr implements Expr { | 9 final class TableExpr implements Expr { |
| 9 | 10 |
| 10 static class Field { | 11 static class Field { |
| 16 this.value = value; | 17 this.value = value; |
| 17 } | 18 } |
| 18 } | 19 } |
| 19 | 20 |
| 20 private final Field[] fields; | 21 private final Field[] fields; |
| 22 private final Expressions expressions; | |
| 21 | 23 |
| 22 TableExpr(Field[] fields) { | 24 TableExpr(Field[] fields,Expressions expressions) { |
| 23 this.fields = fields; | 25 this.fields = fields; |
| 26 this.expressions = expressions; | |
| 24 } | 27 } |
| 25 | 28 |
| 26 @Override public Object eval(LuaState lua) throws LuaException { | 29 @Override public Object eval(LuaState lua) throws LuaException { |
| 27 LuaTable table = new LuaTable(); | 30 LuaTable table = new LuaTable(); |
| 28 for( Field field : fields ) { | 31 for( Field field : fields ) { |
| 29 table.set( field.key.eval(lua), field.value.eval(lua) ); | 32 table.set( field.key.eval(lua), field.value.eval(lua) ); |
| 30 } | 33 } |
| 34 Object[] a = expressions.eval(lua); | |
| 35 for( int i=0; i<a.length; i++ ) { | |
| 36 table.set( new LuaNumber(i+1), a[i] ); | |
| 37 } | |
| 31 return table; | 38 return table; |
| 32 } | 39 } |
| 33 } | 40 } |
