Mercurial Hosting > luan
changeset 662:ee00a619eec1
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 06 Apr 2016 21:47:45 -0600 |
parents | 1bbb08c0d8f1 |
children | b438a47196bc |
files | core/src/luan/impl/LuanImpl.java core/src/luan/impl/LuanParser.java |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
diff -r 1bbb08c0d8f1 -r ee00a619eec1 core/src/luan/impl/LuanImpl.java --- a/core/src/luan/impl/LuanImpl.java Wed Apr 06 21:19:30 2016 -0600 +++ b/core/src/luan/impl/LuanImpl.java Wed Apr 06 21:47:45 2016 -0600 @@ -224,6 +224,15 @@ throw new LuanException( "attempt to index a " + Luan.type(t) + " value" ); } + public static Object pick(Object o,int i) { + if( i < 1 ) + throw new RuntimeException(); + if( !(o instanceof Object[]) ) + return null; + Object[] a = (Object[])o; + return i<a.length ? a[i] : null; + } + public static Object[] concatArgs(Object o1,Object o2) { if( o1 instanceof Object[] ) { Object[] a1 = (Object[])o1;
diff -r 1bbb08c0d8f1 -r ee00a619eec1 core/src/luan/impl/LuanParser.java --- a/core/src/luan/impl/LuanParser.java Wed Apr 06 21:19:30 2016 -0600 +++ b/core/src/luan/impl/LuanParser.java Wed Apr 06 21:47:45 2016 -0600 @@ -583,7 +583,7 @@ ExpString t = new ExpString("t",true,false); sb.append( vars.get(0).set(new ExpString("t",true,false)).code ); for( int i=1; i<n; i++ ) { - sb.append( vars.get(0).set(new ExpString("LuanImpl.pick(t,"+i+")",true,false)).code ); + sb.append( vars.get(i).set(new ExpString("LuanImpl.pick(t,"+i+")",true,false)).code ); } return parser.success( new StmtString(sb.toString()) ); }