annotate core/src/luan/LuanJavaFunction.java @ 434:472fc70853cd

remove more generics
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 May 2015 16:21:25 -0600
parents d9df6d6cb927
children bf5e62a9090c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1 package luan;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
3 import java.lang.reflect.Array;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
4 import java.lang.reflect.Method;
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
5 import java.lang.reflect.Constructor;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
6 import java.lang.reflect.InvocationTargetException;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
7 import java.util.List;
209
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
8 import java.util.ArrayList;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
9 import java.util.Map;
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
10 import java.util.HashMap;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
11 import java.util.Set;
55
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
12 import java.util.Arrays;
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
13 import java.util.Collection;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
14
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
15
213
4a27f24ce2b5 Make LuanJavaFunction not DeepCloneable. There is no reason for most to be DeepCloneable and those that should be can be made DeepCloneable individually.
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 212
diff changeset
16 public final class LuanJavaFunction extends LuanFunction {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
17 private final JavaMethod method;
197
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
18 private Object obj;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
19 private final RtnConverter rtnConverter;
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
20 private final boolean takesLuaState;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
21 private final ArgConverter[] argConverters;
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
22 private final Class varArgCls;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
23
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
24 public LuanJavaFunction(Method method,Object obj) {
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
25 this( JavaMethod.of(method), obj );
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
26 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
27
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
28 public LuanJavaFunction(Constructor constr,Object obj) {
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
29 this( JavaMethod.of(constr), obj );
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
30 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
31
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
32 private LuanJavaFunction(JavaMethod method,Object obj) {
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
33 this.method = method;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
34 this.obj = obj;
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
35 this.rtnConverter = getRtnConverter(method);
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
36 this.takesLuaState = takesLuaState(method);
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
37 this.argConverters = getArgConverters(takesLuaState,method);
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
38 if( method.isVarArgs() ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
39 Class[] paramTypes = method.getParameterTypes();
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
40 this.varArgCls = paramTypes[paramTypes.length-1].getComponentType();
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
41 } else {
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
42 this.varArgCls = null;
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
43 }
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
44 }
213
4a27f24ce2b5 Make LuanJavaFunction not DeepCloneable. There is no reason for most to be DeepCloneable and those that should be can be made DeepCloneable individually.
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 212
diff changeset
45 /*
197
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
46 private LuanJavaFunction(LuanJavaFunction f) {
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
47 this.method = f.method;
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
48 this.rtnConverter = f.rtnConverter;
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
49 this.takesLuaState = f.takesLuaState;
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
50 this.argConverters = f.argConverters;
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
51 this.varArgCls = f.varArgCls;
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
52 }
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
53
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
54 @Override public LuanJavaFunction shallowClone() {
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
55 return obj==null ? this : new LuanJavaFunction(this);
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
56 }
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
57
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
58 @Override public void deepenClone(LuanJavaFunction clone,DeepCloner cloner) {
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
59 clone.obj = cloner.get(obj);
4c96cb73dd93 fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 171
diff changeset
60 }
213
4a27f24ce2b5 Make LuanJavaFunction not DeepCloneable. There is no reason for most to be DeepCloneable and those that should be can be made DeepCloneable individually.
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 212
diff changeset
61 */
60
a68ccb7aaa9c implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 57
diff changeset
62 @Override public String toString() {
a68ccb7aaa9c implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 57
diff changeset
63 return "java-function: " + method;
a68ccb7aaa9c implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 57
diff changeset
64 }
a68ccb7aaa9c implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 57
diff changeset
65
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
66 public Class[] getParameterTypes() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
67 return method.getParameterTypes();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
68 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
69
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
70 @Override public Object call(LuanState luan,Object[] args) throws LuanException {
55
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
71 try {
210
e84655b4c45e better exception handling
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 209
diff changeset
72 args = fixArgs(luan,args);
68
877288464542 better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 67
diff changeset
73 return doCall(luan,args);
55
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
74 } catch(IllegalArgumentException e) {
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
75 checkArgs(luan,args);
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
76 throw e;
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
77 }
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
78 }
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
79
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
80 public Object rawCall(LuanState luan,Object[] args) throws LuanException {
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
81 args = fixArgs(luan,args);
68
877288464542 better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 67
diff changeset
82 return doCall(luan,args);
877288464542 better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 67
diff changeset
83 }
877288464542 better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 67
diff changeset
84
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
85 private Object doCall(LuanState luan,Object[] args) throws LuanException {
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
86 Object rtn;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
87 try {
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
88 rtn = method.invoke(obj,args);
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
89 } catch(IllegalAccessException e) {
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 123
diff changeset
90 throw new RuntimeException("method = "+method,e);
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
91 } catch(InvocationTargetException e) {
40
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
92 Throwable cause = e.getCause();
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
93 if( cause instanceof Error )
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
94 throw (Error)cause;
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
95 if( cause instanceof LuanException )
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
96 throw (LuanException)cause;
249
9737ebb9aaa0 handle LuanExitException
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 244
diff changeset
97 if( cause instanceof LuanExitException )
9737ebb9aaa0 handle LuanExitException
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 244
diff changeset
98 throw (LuanExitException)cause;
130
0594c132888b cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 129
diff changeset
99 throw luan.exception(cause);
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
100 } catch(InstantiationException e) {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
101 throw new RuntimeException(e);
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
102 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
103 return rtnConverter.convert(rtn);
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
104 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
105
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
106 private static final Map primitiveMap = new HashMap();
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
107 static {
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
108 primitiveMap.put(Boolean.TYPE,Boolean.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
109 primitiveMap.put(Character.TYPE,Character.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
110 primitiveMap.put(Byte.TYPE,Byte.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
111 primitiveMap.put(Short.TYPE,Short.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
112 primitiveMap.put(Integer.TYPE,Integer.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
113 primitiveMap.put(Long.TYPE,Long.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
114 primitiveMap.put(Float.TYPE,Float.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
115 primitiveMap.put(Double.TYPE,Double.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
116 primitiveMap.put(Void.TYPE,Void.class);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
117 }
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
118
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
119 private void checkArgs(LuanState luan,Object[] args) throws LuanException {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
120 Class[] a = getParameterTypes();
69
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 68
diff changeset
121 int start = takesLuaState ? 1 : 0;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 68
diff changeset
122 for( int i=start; i<a.length; i++ ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
123 Class paramType = a[i];
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
124 Class type = paramType;
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
125 if( type.isPrimitive() )
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
126 type = (Class)primitiveMap.get(type);
67
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
127 Object arg = args[i];
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
128 if( !type.isInstance(arg) ) {
67
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
129 String expected = paramType.getSimpleName();
210
e84655b4c45e better exception handling
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 209
diff changeset
130 if( i==a.length-1 && method.isVarArgs() )
e84655b4c45e better exception handling
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 209
diff changeset
131 expected = paramType.getComponentType().getSimpleName()+"...";
67
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
132 if( arg==null ) {
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
133 if( paramType.isPrimitive() )
130
0594c132888b cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 129
diff changeset
134 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)");
67
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
135 } else {
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
136 String got = arg.getClass().getSimpleName();
130
0594c132888b cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 129
diff changeset
137 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got "+got+")");
67
8ca58ab6919b fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 64
diff changeset
138 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
139 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
140 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
141 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
142
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
143 private Object[] fixArgs(LuanState luan,Object[] args) throws LuanException {
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
144 int n = argConverters.length;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
145 Object[] rtn;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
146 int start = 0;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
147 if( !takesLuaState && varArgCls==null && args.length == n ) {
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
148 rtn = args;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
149 } else {
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
150 if( takesLuaState )
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
151 n++;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
152 rtn = new Object[n];
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
153 if( takesLuaState ) {
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
154 rtn[start++] = luan;
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
155 }
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
156 n = argConverters.length;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
157 if( varArgCls != null ) {
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
158 n--;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
159 if( args.length < argConverters.length ) {
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
160 rtn[rtn.length-1] = Array.newInstance(varArgCls,0);
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
161 } else {
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
162 int len = args.length - n;
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
163 Object varArgs = Array.newInstance(varArgCls,len);
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
164 ArgConverter ac = argConverters[n];
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
165 for( int i=0; i<len; i++ ) {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
166 Array.set( varArgs, i, ac.convert(luan,args[n+i]) );
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
167 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
168 rtn[rtn.length-1] = varArgs;
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
169 }
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
170 }
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
171 System.arraycopy(args,0,rtn,start,Math.min(args.length,n));
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
172 }
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
173 for( int i=0; i<n; i++ ) {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
174 rtn[start+i] = argConverters[i].convert(luan,rtn[start+i]);
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
175 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
176 return rtn;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
177 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
178
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
179
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
180 private interface RtnConverter {
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
181 public Object convert(Object obj);
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
182 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
183
123
d7be9b3abf1a minor - rename LuanFunction.EMPTY to NOTHING
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 115
diff changeset
184 private static final RtnConverter RTN_NOTHING = new RtnConverter() {
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
185 @Override public Object[] convert(Object obj) {
123
d7be9b3abf1a minor - rename LuanFunction.EMPTY to NOTHING
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 115
diff changeset
186 return NOTHING;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
187 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
188 };
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
189
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
190 private static final RtnConverter RTN_SAME = new RtnConverter() {
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
191 @Override public Object convert(Object obj) {
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
192 return obj;
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 4
diff changeset
193 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 4
diff changeset
194 };
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 4
diff changeset
195
209
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
196 private static final RtnConverter RTN_ARRAY = new RtnConverter() {
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
197 @Override public Object convert(Object obj) {
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
198 if( obj == null )
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
199 return null;
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
200 Object[] a = new Object[Array.getLength(obj)];
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
201 for( int i=0; i<a.length; i++ ) {
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
202 a[i] = Array.get(obj,i);
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
203 }
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
204 return new LuanTable(new ArrayList<Object>(Arrays.asList(a)));
209
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
205 }
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
206 };
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
207
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
208 private static RtnConverter getRtnConverter(JavaMethod m) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
209 Class rtnType = m.getReturnType();
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
210 if( rtnType == Void.TYPE )
123
d7be9b3abf1a minor - rename LuanFunction.EMPTY to NOTHING
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 115
diff changeset
211 return RTN_NOTHING;
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
212 if( !m.isLuan() && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() ) {
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
213 //System.out.println("qqqqqq "+m);
209
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 197
diff changeset
214 return RTN_ARRAY;
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
215 }
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 98
diff changeset
216 return RTN_SAME;
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
217 }
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
218
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
219 private static boolean isNumber(Class rtnType) {
113
8c706d6eb5dc add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 111
diff changeset
220 return rtnType == Short.TYPE
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
221 || rtnType == Integer.TYPE
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
222 || rtnType == Long.TYPE
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
223 || rtnType == Float.TYPE
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
224 || rtnType == Double.TYPE
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
225 ;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
226 }
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
227
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
228 private interface ArgConverter {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
229 public Object convert(LuanState luan,Object obj) throws LuanException;
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
230 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
231
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
232 private static final ArgConverter ARG_SAME = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
233 public Object convert(LuanState luan,Object obj) {
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
234 return obj;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
235 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
236 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
237 return "ARG_SAME";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
238 }
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
239 };
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
240
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
241 private static final ArgConverter ARG_BOOLEAN = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
242 public Object convert(LuanState luan,Object obj) {
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
243 return Luan.toBoolean(obj);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
244 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
245 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
246 return "ARG_BOOLEAN";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
247 }
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
248 };
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
249
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
250 private static final ArgConverter ARG_BOOLEAN_OBJ = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
251 public Object convert(LuanState luan,Object obj) {
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
252 return obj==null ? null : Luan.toBoolean(obj);
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
253 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
254 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
255 return "ARG_BOOLEAN_OBJ";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
256 }
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
257 };
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
258
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
259 private static final ArgConverter ARG_DOUBLE = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
260 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
261 if( obj instanceof Double )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
262 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
263 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
264 Number n = (Number)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
265 return n.doubleValue();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
266 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
267 if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
268 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
269 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
270 return Double.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
271 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
272 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
273 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
274 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
275 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
276 return "ARG_DOUBLE";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
277 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
278 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
279
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
280 private static final ArgConverter ARG_FLOAT = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
281 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
282 if( obj instanceof Float )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
283 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
284 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
285 Number n = (Number)obj;
98
3a0ff21f0c96 fix LuanJavaFunction.ARG_FLOAT
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 95
diff changeset
286 return n.floatValue();
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
287 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
288 if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
289 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
290 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
291 return Float.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
292 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
293 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
294 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
295 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
296 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
297 return "ARG_FLOAT";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
298 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
299 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
300
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
301 private static final ArgConverter ARG_LONG = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
302 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
303 if( obj instanceof Long )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
304 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
305 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
306 Number n = (Number)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
307 long r = n.longValue();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
308 if( r==n.doubleValue() )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
309 return r;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
310 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
311 else if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
312 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
313 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
314 return Long.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
315 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
316 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
317 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
318 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
319 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
320 return "ARG_LONG";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
321 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
322 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
323
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
324 private static final ArgConverter ARG_INTEGER = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
325 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
326 if( obj instanceof Integer )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
327 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
328 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
329 Number n = (Number)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
330 int r = n.intValue();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
331 if( r==n.doubleValue() )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
332 return r;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
333 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
334 else if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
335 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
336 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
337 return Integer.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
338 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
339 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
340 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
341 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
342 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
343 return "ARG_INTEGER";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
344 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
345 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
346
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
347 private static final ArgConverter ARG_SHORT = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
348 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
349 if( obj instanceof Short )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
350 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
351 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
352 Number n = (Number)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
353 short r = n.shortValue();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
354 if( r==n.doubleValue() )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
355 return r;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
356 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
357 else if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
358 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
359 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
360 return Short.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
361 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
362 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
363 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
364 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
365 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
366 return "ARG_SHORT";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
367 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
368 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
369
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
370 private static final ArgConverter ARG_BYTE = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
371 public Object convert(LuanState luan,Object obj) {
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
372 if( obj instanceof Byte )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
373 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
374 if( obj instanceof Number ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
375 Number n = (Number)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
376 byte r = n.byteValue();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
377 if( r==n.doubleValue() )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
378 return r;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
379 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
380 else if( obj instanceof String ) {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
381 String s = (String)obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
382 try {
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
383 return Byte.valueOf(s);
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
384 } catch(NumberFormatException e) {}
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
385 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
386 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
387 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
388 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
389 return "ARG_BYTE";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
390 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
391 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
392
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
393 private static final ArgConverter ARG_TABLE = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
394 public Object convert(LuanState luan,Object obj) {
86
6db8f286fa6c _ENV is per module, not global
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 69
diff changeset
395 if( obj == null )
6db8f286fa6c _ENV is per module, not global
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 69
diff changeset
396 return null;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
397 if( obj instanceof List ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
398 return new LuanTable((List)obj);
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
399 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
400 if( obj instanceof Map ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
401 return new LuanTable((Map)obj);
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
402 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
403 if( obj instanceof Set ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
404 return new LuanTable((Set)obj);
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
405 }
55
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
406 Class cls = obj.getClass();
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
407 if( cls.isArray() && !cls.getComponentType().isPrimitive() ) {
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
408 Object[] a = (Object[])obj;
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
409 return new LuanTable(Arrays.asList(a));
55
9381b23ea9e1 various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 49
diff changeset
410 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
411 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
412 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
413 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
414 return "ARG_TABLE";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
415 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
416 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
417
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
418 private static final ArgConverter ARG_MAP = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
419 public Object convert(LuanState luan,Object obj) throws LuanException {
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
420 if( obj instanceof LuanTable ) {
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
421 LuanTable t = (LuanTable)obj;
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
422 return t.asMap(luan);
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
423 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
424 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
425 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
426 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
427 return "ARG_MAP";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
428 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
429 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
430
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
431 private static final ArgConverter ARG_LIST = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
432 public Object convert(LuanState luan,Object obj) {
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
433 if( obj instanceof LuanTable ) {
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
434 LuanTable t = (LuanTable)obj;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
435 if( t.isList() )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
436 return t.asList();
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
437 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
438 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
439 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
440 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
441 return "ARG_LIST";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
442 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
443 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
444
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
445 private static final ArgConverter ARG_SET = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
446 public Object convert(LuanState luan,Object obj) throws LuanException {
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
447 if( obj instanceof LuanTable ) {
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
448 LuanTable t = (LuanTable)obj;
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
449 if( t.isSet(luan) )
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
450 return t.asSet(luan);
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
451 }
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
452 return obj;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
453 }
244
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
454 @Override public String toString() {
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
455 return "ARG_SET";
0a8e6fdb62f0 fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 221
diff changeset
456 }
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
457 };
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
458
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
459 private static final ArgConverter ARG_COLLECTION = new ArgConverter() {
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
460 public Object convert(LuanState luan,Object obj) throws LuanException {
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
461 if( obj instanceof LuanTable ) {
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
462 LuanTable t = (LuanTable)obj;
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
463 if( t.isList() )
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
464 return t.asList();
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
465 if( t.isSet(luan) )
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
466 return t.asSet(luan);
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
467 }
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
468 return obj;
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
469 }
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
470 @Override public String toString() {
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
471 return "ARG_COLLECTION";
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
472 }
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
473 };
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
474
57
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
475 private static class ArgArray implements ArgConverter {
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
476 private final Object[] a;
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
477
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
478 ArgArray(Class cls) {
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
479 a = (Object[])Array.newInstance(cls.getComponentType(),0);
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
480 }
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
481
432
d9df6d6cb927 finish fixing LuanTable to use metatables
Franklin Schmidt <fschmidt@gmail.com>
parents: 431
diff changeset
482 public Object convert(LuanState luan,Object obj) {
408
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
483 if( obj instanceof LuanTable ) {
1b38de2b1845 merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents: 396
diff changeset
484 LuanTable t = (LuanTable)obj;
57
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
485 if( t.isList() ) {
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
486 try {
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
487 return t.asList().toArray(a);
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
488 } catch(ArrayStoreException e) {}
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
489 }
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
490 }
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
491 return obj;
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
492 }
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
493 }
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
494
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
495 private static boolean takesLuaState(JavaMethod m) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
496 Class[] paramTypes = m.getParameterTypes();
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
497 return paramTypes.length > 0 && paramTypes[0].equals(LuanState.class);
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
498 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
499
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
500 private static ArgConverter[] getArgConverters(boolean takesLuaState,JavaMethod m) {
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
501 final boolean isVarArgs = m.isVarArgs();
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
502 Class[] paramTypes = m.getParameterTypes();
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
503 if( takesLuaState ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
504 Class[] t = new Class[paramTypes.length-1];
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
505 System.arraycopy(paramTypes,1,t,0,t.length);
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
506 paramTypes = t;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
507 }
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
508 ArgConverter[] a = new ArgConverter[paramTypes.length];
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
509 for( int i=0; i<a.length; i++ ) {
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
510 Class paramType = paramTypes[i];
4
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
511 if( isVarArgs && i == a.length-1 )
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
512 paramType = paramType.getComponentType();
24fd6381caca add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 2
diff changeset
513 a[i] = getArgConverter(paramType);
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
514 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
515 return a;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
516 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
517
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
518 private static ArgConverter getArgConverter(Class cls) {
95
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
519 if( cls == Boolean.TYPE )
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
520 return ARG_BOOLEAN;
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
521 if( cls.equals(Boolean.class) )
9aa7d5f20333 in LuanJavaFunction, fix primitive type checking and add boolean conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
522 return ARG_BOOLEAN_OBJ;
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
523 if( cls == Double.TYPE || cls.equals(Double.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
524 return ARG_DOUBLE;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
525 if( cls == Float.TYPE || cls.equals(Float.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
526 return ARG_FLOAT;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
527 if( cls == Long.TYPE || cls.equals(Long.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
528 return ARG_LONG;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
529 if( cls == Integer.TYPE || cls.equals(Integer.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
530 return ARG_INTEGER;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
531 if( cls == Short.TYPE || cls.equals(Short.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
532 return ARG_SHORT;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
533 if( cls == Byte.TYPE || cls.equals(Byte.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
534 return ARG_BYTE;
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 47
diff changeset
535 if( cls.equals(LuanTable.class) )
47
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
536 return ARG_TABLE;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
537 if( cls.equals(Map.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
538 return ARG_MAP;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
539 if( cls.equals(List.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
540 return ARG_LIST;
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
541 if( cls.equals(Set.class) )
659c7139e903 better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
542 return ARG_SET;
396
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
543 if( cls.equals(Collection.class) )
ba8b0aae6453 work on manual;
Franklin Schmidt <fschmidt@gmail.com>
parents: 297
diff changeset
544 return ARG_COLLECTION;
57
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
545 if( cls.isArray() && !cls.getComponentType().isPrimitive() )
19ca9c4c6c7f auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
546 return new ArgArray(cls);
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
547 return ARG_SAME;
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
548 }
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
549
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
550
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
551
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
552 private static abstract class JavaMethod {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
553 abstract boolean isVarArgs();
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
554 abstract Class[] getParameterTypes();
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
555 abstract Object invoke(Object obj,Object... args)
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
556 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException;
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
557 abstract Class getReturnType();
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
558 abstract boolean isLuan();
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
559
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
560 static JavaMethod of(final Method m) {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
561 return new JavaMethod() {
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
562 @Override boolean isVarArgs() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
563 return m.isVarArgs();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
564 }
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
565 @Override Class[] getParameterTypes() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
566 return m.getParameterTypes();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
567 }
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
568 @Override Object invoke(Object obj,Object... args)
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
569 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
570 {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
571 return m.invoke(obj,args);
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
572 }
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
573 @Override Class getReturnType() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
574 return m.getReturnType();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
575 }
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
576 @Override boolean isLuan() {
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
577 return m.getAnnotation(LuanMethod.class) != null;
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
578 }
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
579 @Override public String toString() {
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
580 return m.toString();
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
581 }
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
582 };
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
583 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
584
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
585 static JavaMethod of(final Constructor c) {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
586 return new JavaMethod() {
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
587 @Override boolean isVarArgs() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
588 return c.isVarArgs();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
589 }
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
590 @Override Class[] getParameterTypes() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
591 return c.getParameterTypes();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
592 }
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
593 @Override Object invoke(Object obj,Object... args)
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
594 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
595 {
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
596 return c.newInstance(args);
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
597 }
434
472fc70853cd remove more generics
Franklin Schmidt <fschmidt@gmail.com>
parents: 432
diff changeset
598 @Override Class getReturnType() {
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
599 return c.getDeclaringClass();
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
600 }
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
601 @Override boolean isLuan() {
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
602 return false;
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 249
diff changeset
603 }
43
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
604 @Override public String toString() {
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
605 return c.toString();
80b67b1a653c implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
606 }
37
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
607 };
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
608 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
609
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
610 }
8a57ebfdfd78 add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
611
1
2df768b926aa start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
612 }