comparison core/src/luan/LuanJavaFunction.java @ 447:0bd42e774c50

add assert_binary; improve wrong type messages;
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 May 2015 17:19:43 -0600
parents bbad2d06f728
children b8ddd55c9b11
comparison
equal deleted inserted replaced
446:bbad2d06f728 447:0bd42e774c50
124 Class type = paramType; 124 Class type = paramType;
125 if( type.isPrimitive() ) 125 if( type.isPrimitive() )
126 type = (Class)primitiveMap.get(type); 126 type = (Class)primitiveMap.get(type);
127 Object arg = args[i]; 127 Object arg = args[i];
128 if( !type.isInstance(arg) ) { 128 if( !type.isInstance(arg) ) {
129 String expected = paramType.getSimpleName(); 129 String expected;
130 if( i==a.length-1 && method.isVarArgs() ) 130 if( i==a.length-1 && method.isVarArgs() )
131 expected = paramType.getComponentType().getSimpleName()+"..."; 131 expected = fixType(paramType.getComponentType().getSimpleName())+"...";
132 else
133 expected = fixType(paramType.getSimpleName());
132 if( arg==null ) { 134 if( arg==null ) {
133 if( paramType.isPrimitive() ) 135 if( paramType.isPrimitive() )
134 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)"); 136 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)");
135 } else { 137 } else {
136 String got = arg.getClass().getSimpleName(); 138 String got = fixType(arg.getClass().getSimpleName());
137 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got "+got+")"); 139 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got "+got+")");
138 } 140 }
139 } 141 }
140 } 142 }
143 }
144
145 private static String fixType(String type) {
146 if( type.equals("byte[]") )
147 return "binary";
148 if( type.equals("Double") )
149 return "number";
150 if( type.equals("LuanTable") )
151 return "table";
152 if( type.equals("Boolean") )
153 return "boolean";
154 if( type.equals("String") )
155 return "string";
156 if( type.equals("Closure") )
157 return "function";
158 if( type.equals("LuanJavaFunction") )
159 return "function";
160 return type;
141 } 161 }
142 162
143 private Object[] fixArgs(LuanState luan,Object[] args) throws LuanException { 163 private Object[] fixArgs(LuanState luan,Object[] args) throws LuanException {
144 int n = argConverters.length; 164 int n = argConverters.length;
145 Object[] rtn; 165 Object[] rtn;