changeset 861:cdab48877cfe

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 28 Sep 2016 13:50:22 -0600
parents 626815a4b19b
children 2bb375e94f64
files src/luan/LuanJavaFunction.java
diffstat 1 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanJavaFunction.java	Tue Sep 27 22:20:07 2016 -0600
+++ b/src/luan/LuanJavaFunction.java	Wed Sep 28 13:50:22 2016 -0600
@@ -11,7 +11,6 @@
 import java.util.Set;
 import java.util.Arrays;
 import java.util.Collection;
-import luan.impl.Closure;
 
 
 public final class LuanJavaFunction extends LuanFunction {
@@ -111,34 +110,36 @@
 			if( !type.isInstance(arg) ) {
 				String expected;
 				if( i==a.length-1 && method.isVarArgs() )
-					expected = fixType(paramType.getComponentType().getSimpleName())+"...";
+					expected = type(paramType.getComponentType())+"...";
 				else
-					expected = fixType(paramType.getSimpleName());
+					expected = type(paramType);
 				if( arg==null ) {
 					if( paramType.isPrimitive() )
 						throw new LuanException("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)");
 				} else {
-					String got = arg instanceof Closure ? "function" : fixType(arg.getClass().getSimpleName());
+					String got = type(arg.getClass());
 					throw new LuanException("bad argument #"+(i+1-start)+" ("+expected+" expected, got "+got+")");
 				}
 			}
 		}
 	}
 
-	private static String fixType(String type) {
-		if( type.equals("byte[]") )
-			return "binary";
-		if( type.equals("Double") )
+	private static final Class byteArray = new byte[0].getClass();
+
+	private static String type(Class cls) {
+		if( LuanFunction.class.isAssignableFrom(cls) )
+			return "function";
+		if( Boolean.class.isAssignableFrom(cls) )
+			return "boolean";
+		if( String.class.isAssignableFrom(cls) )
+			return "string";
+		if( Number.class.isAssignableFrom(cls) )
 			return "number";
-		if( type.equals("LuanTable") )
+		if( LuanTable.class.isAssignableFrom(cls) )
 			return "table";
-		if( type.equals("Boolean") )
-			return "boolean";
-		if( type.equals("String") )
-			return "string";
-		if( type.equals("LuanJavaFunction") )
-			return "function";
-		return type;
+		if( byteArray.isAssignableFrom(cls) )
+			return "binary";
+		return cls.getName();
 	}
 
 	private Object[] fixArgs(LuanState luan,Object[] args) throws LuanException {