comparison src/luan/impl/LuanImpl.java @ 1089:894786a03d22

check for too many arguments
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 29 Dec 2016 21:26:45 -0700
parents 1a68fc55a80c
children ba4daf107e07
comparison
equal deleted inserted replaced
1088:bae2d0c2576c 1089:894786a03d22
172 if( i < 1 ) 172 if( i < 1 )
173 throw new RuntimeException(); 173 throw new RuntimeException();
174 if( !(o instanceof Object[]) ) 174 if( !(o instanceof Object[]) )
175 return null; 175 return null;
176 Object[] a = (Object[])o; 176 Object[] a = (Object[])o;
177 return pick(a,i);
178 }
179
180 public static Object pick(Object[] a,int i) {
177 return i<a.length ? a[i] : null; 181 return i<a.length ? a[i] : null;
182 }
183
184 public static void noMore(final Object[] a,final int n) throws LuanException {
185 if( a.length > n ) {
186 for( int i=n; i<a.length; i++ ) {
187 if( a[i] != null )
188 throw new LuanException("too many arguments");
189 }
190 }
178 } 191 }
179 192
180 public static Object[] varArgs(Object[] a,int i) { 193 public static Object[] varArgs(Object[] a,int i) {
181 if( i >= a.length ) 194 if( i >= a.length )
182 return LuanFunction.NOTHING; 195 return LuanFunction.NOTHING;