diff src/luan/LuanJavaFunction.java @ 64:177cfdc2bdb3

add type assertions git-svn-id: https://luan-java.googlecode.com/svn/trunk@65 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 17 Jan 2013 19:29:58 +0000
parents a68ccb7aaa9c
children 8ca58ab6919b
line wrap: on
line diff
--- a/src/luan/LuanJavaFunction.java	Wed Jan 09 22:54:50 2013 +0000
+++ b/src/luan/LuanJavaFunction.java	Thu Jan 17 19:29:58 2013 +0000
@@ -81,13 +81,16 @@
 
 	private void checkArgs(LuanState luan,Object[] args) throws LuanException {
 		Class<?>[] a = getParameterTypes();
+		if( takesLuaState ) {
+			Class<?>[] t = new Class<?>[a.length-1];
+			System.arraycopy(a,1,t,0,t.length);
+			a = t;
+		}
 		for( int i=0; i<a.length; i++ ) {
 			if( !a[i].isInstance(args[i]) ) {
-				String got = args[i].getClass().getName();
-				String expected = a[i].getName();
-				if( !takesLuaState )
-					i++;
-				throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+i+" ("+expected+" expected, got "+got+")");
+				String got = args[i].getClass().getSimpleName();
+				String expected = a[i].getSimpleName();
+				throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got "+got+")");
 			}
 		}
 	}