Mercurial Hosting > luan
view core/src/luan/impl/TableExpr.java @ 356:5e34702423a0
better parser error message
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 09:44:07 -0600 |
parents | ec016471c6eb |
children | 23b99a5039b5 |
line wrap: on
line source
package luan.impl; import luan.LuanException; import luan.LuanTable; import luan.LuanSource; import luan.Luan; final class TableExpr extends CodeImpl implements Expr { static class Field { final Expr key; final Expr value; Field(Expr key,Expr value) { this.key = key; this.value = value; } } private final Field[] fields; private final Expressions expressions; TableExpr(LuanSource.Element se,Field[] fields,Expressions expressions) { super(se); this.fields = fields; this.expressions = expressions; } @Override public Object eval(LuanStateImpl luan) throws LuanException { LuanTable table = Luan.newTable(); for( Field field : fields ) { table.put( field.key.eval(luan), field.value.eval(luan) ); } Object obj = expressions.eval(luan); if( obj instanceof Object[] ) { Object[] a = (Object[])obj; for( int i=0; i<a.length; i++ ) { table.put( i+1, a[i] ); } } else { table.put( 1, obj ); } return table; } }