Mercurial Hosting > luan
comparison src/luan/LuanJavaFunction.java @ 49:8ede219cd111
add WebShell
git-svn-id: https://luan-java.googlecode.com/svn/trunk@50 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 19:35:04 +0000 |
parents | 64ecb7a3aad7 |
children | 9381b23ea9e1 |
comparison
equal
deleted
inserted
replaced
48:64ecb7a3aad7 | 49:8ede219cd111 |
---|---|
41 | 41 |
42 public Class<?>[] getParameterTypes() { | 42 public Class<?>[] getParameterTypes() { |
43 return method.getParameterTypes(); | 43 return method.getParameterTypes(); |
44 } | 44 } |
45 | 45 |
46 @Override public Object[] call(LuanState lua,Object[] args) throws LuanException { | 46 @Override public Object[] call(LuanState luan,Object[] args) throws LuanException { |
47 args = fixArgs(lua,args); | 47 args = fixArgs(luan,args); |
48 Object rtn; | 48 Object rtn; |
49 try { | 49 try { |
50 rtn = method.invoke(obj,args); | 50 rtn = method.invoke(obj,args); |
51 } catch(IllegalArgumentException e) { | 51 } catch(IllegalArgumentException e) { |
52 checkArgs(lua,args); | 52 checkArgs(luan,args); |
53 throw e; | 53 throw e; |
54 } catch(IllegalAccessException e) { | 54 } catch(IllegalAccessException e) { |
55 throw new RuntimeException(e); | 55 throw new RuntimeException(e); |
56 } catch(InvocationTargetException e) { | 56 } catch(InvocationTargetException e) { |
57 Throwable cause = e.getCause(); | 57 Throwable cause = e.getCause(); |
66 throw new RuntimeException(e); | 66 throw new RuntimeException(e); |
67 } | 67 } |
68 return rtnConverter.convert(rtn); | 68 return rtnConverter.convert(rtn); |
69 } | 69 } |
70 | 70 |
71 private void checkArgs(LuanState lua,Object[] args) throws LuanException { | 71 private void checkArgs(LuanState luan,Object[] args) throws LuanException { |
72 Class<?>[] a = getParameterTypes(); | 72 Class<?>[] a = getParameterTypes(); |
73 for( int i=0; i<a.length; i++ ) { | 73 for( int i=0; i<a.length; i++ ) { |
74 if( !a[i].isInstance(args[i]) ) { | 74 if( !a[i].isInstance(args[i]) ) { |
75 String got = args[i].getClass().getName(); | 75 String got = args[i].getClass().getName(); |
76 String expected = a[i].getName(); | 76 String expected = a[i].getName(); |
77 if( !takesLuaState ) | 77 if( !takesLuaState ) |
78 i++; | 78 i++; |
79 throw new LuanException(lua,LuanElement.JAVA,"bad argument #"+i+" ("+expected+" expected, got "+got+")"); | 79 throw new LuanException(luan,LuanElement.JAVA,"bad argument #"+i+" ("+expected+" expected, got "+got+")"); |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 private Object[] fixArgs(LuanState lua,Object[] args) { | 84 private Object[] fixArgs(LuanState luan,Object[] args) { |
85 int n = argConverters.length; | 85 int n = argConverters.length; |
86 Object[] rtn; | 86 Object[] rtn; |
87 int start = 0; | 87 int start = 0; |
88 if( !takesLuaState && varArgCls==null && args.length == n ) { | 88 if( !takesLuaState && varArgCls==null && args.length == n ) { |
89 rtn = args; | 89 rtn = args; |
90 } else { | 90 } else { |
91 if( takesLuaState ) | 91 if( takesLuaState ) |
92 n++; | 92 n++; |
93 rtn = new Object[n]; | 93 rtn = new Object[n]; |
94 if( takesLuaState ) { | 94 if( takesLuaState ) { |
95 rtn[start++] = lua; | 95 rtn[start++] = luan; |
96 } | 96 } |
97 n = argConverters.length; | 97 n = argConverters.length; |
98 if( varArgCls != null ) { | 98 if( varArgCls != null ) { |
99 n--; | 99 n--; |
100 if( args.length < argConverters.length ) { | 100 if( args.length < argConverters.length ) { |