Mercurial Hosting > luan
changeset 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 | f7e17cfb35f9 |
children | 877288464542 |
files | src/luan/LuanJavaFunction.java |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
diff -r f7e17cfb35f9 -r 8ca58ab6919b src/luan/LuanJavaFunction.java --- a/src/luan/LuanJavaFunction.java Tue Jan 22 00:00:27 2013 +0000 +++ b/src/luan/LuanJavaFunction.java Tue Jan 22 21:56:05 2013 +0000 @@ -87,10 +87,17 @@ a = t; } for( int i=0; i<a.length; i++ ) { - if( !a[i].isInstance(args[i]) ) { - 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+")"); + Class<?> paramType = a[i]; + Object arg = args[i]; + if( !paramType.isInstance(arg) ) { + String expected = paramType.getSimpleName(); + if( arg==null ) { + if( paramType.isPrimitive() ) + throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got nil)"); + } else { + String got = arg.getClass().getSimpleName(); + throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+(i+1)+" ("+expected+" expected, got "+got+")"); + } } } }