Mercurial Hosting > luan
comparison core/src/luan/LuanJavaFunction.java @ 297:899253043270
remove PackageLuan.load_lib()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@298 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 16 Dec 2014 03:26:43 +0000 |
parents | 9737ebb9aaa0 |
children | ba8b0aae6453 |
comparison
equal
deleted
inserted
replaced
296:7ea6dfdf81ba | 297:899253043270 |
---|---|
19 private final boolean takesLuaState; | 19 private final boolean takesLuaState; |
20 private final ArgConverter[] argConverters; | 20 private final ArgConverter[] argConverters; |
21 private final Class<?> varArgCls; | 21 private final Class<?> varArgCls; |
22 | 22 |
23 public LuanJavaFunction(Method method,Object obj) { | 23 public LuanJavaFunction(Method method,Object obj) { |
24 this(method,obj,false); | 24 this( JavaMethod.of(method), obj ); |
25 } | |
26 | |
27 public LuanJavaFunction(Method method,Object obj,boolean convertArray) { | |
28 this( JavaMethod.of(method), obj, convertArray ); | |
29 } | 25 } |
30 | 26 |
31 public LuanJavaFunction(Constructor constr,Object obj) { | 27 public LuanJavaFunction(Constructor constr,Object obj) { |
32 this( JavaMethod.of(constr), obj, false ); | 28 this( JavaMethod.of(constr), obj ); |
33 } | 29 } |
34 | 30 |
35 private LuanJavaFunction(JavaMethod method,Object obj,boolean convertArray) { | 31 private LuanJavaFunction(JavaMethod method,Object obj) { |
36 this.method = method; | 32 this.method = method; |
37 this.obj = obj; | 33 this.obj = obj; |
38 this.rtnConverter = getRtnConverter(method,convertArray); | 34 this.rtnConverter = getRtnConverter(method); |
39 this.takesLuaState = takesLuaState(method); | 35 this.takesLuaState = takesLuaState(method); |
40 this.argConverters = getArgConverters(takesLuaState,method); | 36 this.argConverters = getArgConverters(takesLuaState,method); |
41 if( method.isVarArgs() ) { | 37 if( method.isVarArgs() ) { |
42 Class<?>[] paramTypes = method.getParameterTypes(); | 38 Class<?>[] paramTypes = method.getParameterTypes(); |
43 this.varArgCls = paramTypes[paramTypes.length-1].getComponentType(); | 39 this.varArgCls = paramTypes[paramTypes.length-1].getComponentType(); |
206 } | 202 } |
207 return new LuanTableImpl(new ArrayList<Object>(Arrays.asList(a))); | 203 return new LuanTableImpl(new ArrayList<Object>(Arrays.asList(a))); |
208 } | 204 } |
209 }; | 205 }; |
210 | 206 |
211 private static RtnConverter getRtnConverter(JavaMethod m,boolean convertArray) { | 207 private static RtnConverter getRtnConverter(JavaMethod m) { |
212 Class<?> rtnType = m.getReturnType(); | 208 Class<?> rtnType = m.getReturnType(); |
213 if( rtnType == Void.TYPE ) | 209 if( rtnType == Void.TYPE ) |
214 return RTN_NOTHING; | 210 return RTN_NOTHING; |
215 if( convertArray && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() ) | 211 if( !m.isLuan() && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() ) { |
212 //System.out.println("qqqqqq "+m); | |
216 return RTN_ARRAY; | 213 return RTN_ARRAY; |
214 } | |
217 return RTN_SAME; | 215 return RTN_SAME; |
218 } | 216 } |
219 | 217 |
220 private static boolean isNumber(Class<?> rtnType) { | 218 private static boolean isNumber(Class<?> rtnType) { |
221 return rtnType == Short.TYPE | 219 return rtnType == Short.TYPE |
542 abstract boolean isVarArgs(); | 540 abstract boolean isVarArgs(); |
543 abstract Class<?>[] getParameterTypes(); | 541 abstract Class<?>[] getParameterTypes(); |
544 abstract Object invoke(Object obj,Object... args) | 542 abstract Object invoke(Object obj,Object... args) |
545 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException; | 543 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException; |
546 abstract Class<?> getReturnType(); | 544 abstract Class<?> getReturnType(); |
545 abstract boolean isLuan(); | |
547 | 546 |
548 static JavaMethod of(final Method m) { | 547 static JavaMethod of(final Method m) { |
549 return new JavaMethod() { | 548 return new JavaMethod() { |
550 @Override boolean isVarArgs() { | 549 @Override boolean isVarArgs() { |
551 return m.isVarArgs(); | 550 return m.isVarArgs(); |
559 return m.invoke(obj,args); | 558 return m.invoke(obj,args); |
560 } | 559 } |
561 @Override Class<?> getReturnType() { | 560 @Override Class<?> getReturnType() { |
562 return m.getReturnType(); | 561 return m.getReturnType(); |
563 } | 562 } |
563 @Override boolean isLuan() { | |
564 return m.getAnnotation(LuanMethod.class) != null; | |
565 } | |
564 @Override public String toString() { | 566 @Override public String toString() { |
565 return m.toString(); | 567 return m.toString(); |
566 } | 568 } |
567 }; | 569 }; |
568 } | 570 } |
581 return c.newInstance(args); | 583 return c.newInstance(args); |
582 } | 584 } |
583 @Override Class<?> getReturnType() { | 585 @Override Class<?> getReturnType() { |
584 return c.getDeclaringClass(); | 586 return c.getDeclaringClass(); |
585 } | 587 } |
588 @Override boolean isLuan() { | |
589 return false; | |
590 } | |
586 @Override public String toString() { | 591 @Override public String toString() { |
587 return c.toString(); | 592 return c.toString(); |
588 } | 593 } |
589 }; | 594 }; |
590 } | 595 } |