comparison src/luan/LuanJavaFunction.java @ 67:8ca58ab6919b

fix LuanJavaFunction.checkArgs() for nulls git-svn-id: https://luan-java.googlecode.com/svn/trunk@68 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 22 Jan 2013 21:56:05 +0000
parents 177cfdc2bdb3
children 877288464542
comparison
equal deleted inserted replaced
66:f7e17cfb35f9 67:8ca58ab6919b
85 Class<?>[] t = new Class<?>[a.length-1]; 85 Class<?>[] t = new Class<?>[a.length-1];
86 System.arraycopy(a,1,t,0,t.length); 86 System.arraycopy(a,1,t,0,t.length);
87 a = t; 87 a = t;
88 } 88 }
89 for( int i=0; i<a.length; i++ ) { 89 for( int i=0; i<a.length; i++ ) {
90 if( !a[i].isInstance(args[i]) ) { 90 Class<?> paramType = a[i];
91 String got = args[i].getClass().getSimpleName(); 91 Object arg = args[i];
92 String expected = a[i].getSimpleName(); 92 if( !paramType.isInstance(arg) ) {
93 throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got "+got+")"); 93 String expected = paramType.getSimpleName();
94 if( arg==null ) {
95 if( paramType.isPrimitive() )
96 throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got nil)");
97 } else {
98 String got = arg.getClass().getSimpleName();
99 throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got "+got+")");
100 }
94 } 101 }
95 } 102 }
96 } 103 }
97 104
98 private Object[] fixArgs(LuanState luan,Object[] args) { 105 private Object[] fixArgs(LuanState luan,Object[] args) {