Mercurial Hosting > luan
annotate src/luan/LuanJavaFunction.java @ 1395:9dfff82dfc59
finish postgres work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Sep 2019 01:22:23 -0600 |
parents | 71f067287642 |
children | 8fbcc4747091 |
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 | 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; |
1335 | 20 private final boolean takesLuan; |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
21 private final ArgConverter[] argConverters; |
434 | 22 private final Class varArgCls; |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
23 |
1335 | 24 public LuanJavaFunction(Luan luan,Method method,Object obj) { |
25 this( luan, 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 |
1335 | 28 public LuanJavaFunction(Luan luan,Constructor constr,Object obj) { |
29 this( luan, 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 |
1335 | 32 private LuanJavaFunction(Luan luan,JavaMethod method,Object obj) { |
33 super(luan); | |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
34 this.method = method; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
35 this.obj = obj; |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
36 this.rtnConverter = getRtnConverter(method); |
1335 | 37 this.takesLuan = takesLuan(method); |
38 this.argConverters = getArgConverters(takesLuan,method); | |
4
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
39 if( method.isVarArgs() ) { |
434 | 40 Class[] paramTypes = method.getParameterTypes(); |
4
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
41 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
|
42 } else { |
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
43 this.varArgCls = null; |
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
44 } |
1335 | 45 if( !takesLuan ) |
46 dontClone(); | |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
47 } |
197
4c96cb73dd93
fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
171
diff
changeset
|
48 |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
57
diff
changeset
|
49 @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
|
50 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
|
51 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
57
diff
changeset
|
52 |
783 | 53 public int getParameterCount() { |
54 return argConverters.length; | |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
55 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
56 |
1120
e8fc6712b468
luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
1086
diff
changeset
|
57 public boolean isVarArgs() { |
e8fc6712b468
luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
1086
diff
changeset
|
58 return method.isVarArgs(); |
e8fc6712b468
luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
1086
diff
changeset
|
59 } |
e8fc6712b468
luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
1086
diff
changeset
|
60 |
1335 | 61 @Override public Object call(Object[] args) throws LuanException { |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
62 try { |
1335 | 63 args = fixArgs(args); |
64 return doCall(args); | |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
65 } catch(IllegalArgumentException e) { |
646
cdc70de628b5
simplify LuanException
Franklin Schmidt <fschmidt@gmail.com>
parents:
578
diff
changeset
|
66 checkArgs(args); |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
67 throw e; |
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
68 } |
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
69 } |
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
70 |
1335 | 71 public Object rawCall(Object[] args) throws LuanException { |
72 args = fixArgs(args); | |
73 return doCall(args); | |
68
877288464542
better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
67
diff
changeset
|
74 } |
877288464542
better type checking
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
67
diff
changeset
|
75 |
1335 | 76 private Object doCall(Object[] args) throws LuanException { |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
77 Object rtn; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
78 try { |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
79 rtn = method.invoke(obj,args); |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
80 } catch(IllegalAccessException e) { |
129
486a0641bca4
add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
123
diff
changeset
|
81 throw new RuntimeException("method = "+method,e); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
82 } catch(InvocationTargetException e) { |
40
e3624b7cd603
implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
37
diff
changeset
|
83 Throwable cause = e.getCause(); |
e3624b7cd603
implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
37
diff
changeset
|
84 if( cause instanceof Error ) |
e3624b7cd603
implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
37
diff
changeset
|
85 throw (Error)cause; |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
47
diff
changeset
|
86 if( cause instanceof LuanException ) |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
47
diff
changeset
|
87 throw (LuanException)cause; |
646
cdc70de628b5
simplify LuanException
Franklin Schmidt <fschmidt@gmail.com>
parents:
578
diff
changeset
|
88 throw new LuanException(cause); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
89 } catch(InstantiationException e) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
90 throw new RuntimeException(e); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
91 } |
1335 | 92 return rtnConverter.convert(rtn); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
93 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
94 |
434 | 95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 } |
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 |
646
cdc70de628b5
simplify LuanException
Franklin Schmidt <fschmidt@gmail.com>
parents:
578
diff
changeset
|
108 private void checkArgs(Object[] args) throws LuanException { |
783 | 109 Class[] a = method.getParameterTypes(); |
1335 | 110 int start = takesLuan ? 1 : 0; |
69
aeedefd3e3f3
minor
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
68
diff
changeset
|
111 for( int i=start; i<a.length; i++ ) { |
434 | 112 Class paramType = a[i]; |
113 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
|
114 if( type.isPrimitive() ) |
434 | 115 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
|
116 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
|
117 if( !type.isInstance(arg) ) { |
447 | 118 String expected; |
210
e84655b4c45e
better exception handling
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
209
diff
changeset
|
119 if( i==a.length-1 && method.isVarArgs() ) |
1080 | 120 expected = fixType(paramType.getComponentType().getSimpleName())+"..."; |
447 | 121 else |
1080 | 122 expected = fixType(paramType.getSimpleName()); |
67
8ca58ab6919b
fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
123 if( arg==null ) { |
8ca58ab6919b
fix LuanJavaFunction.checkArgs() for nulls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
124 if( paramType.isPrimitive() ) |
646
cdc70de628b5
simplify LuanException
Franklin Schmidt <fschmidt@gmail.com>
parents:
578
diff
changeset
|
125 throw new LuanException("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
|
126 } else { |
1356 | 127 String got; |
128 if( arg instanceof LuanFunction ) { | |
129 got = "function"; | |
130 } else { | |
131 got = fixType(arg.getClass().getSimpleName()); | |
132 if( got.equals("") ) | |
133 got = arg.getClass().toString(); | |
134 } | |
646
cdc70de628b5
simplify LuanException
Franklin Schmidt <fschmidt@gmail.com>
parents:
578
diff
changeset
|
135 throw new LuanException("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
|
136 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
137 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
138 } |
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 |
1080 | 141 private static String fixType(String type) { |
142 if( type.equals("byte[]") ) | |
143 return "binary"; | |
144 if( type.equals("Double") ) | |
145 return "number"; | |
146 if( type.equals("LuanTable") ) | |
147 return "table"; | |
148 if( type.equals("Boolean") ) | |
861 | 149 return "boolean"; |
1080 | 150 if( type.equals("String") ) |
861 | 151 return "string"; |
1356 | 152 if( type.equals("LuanClosure") ) |
1080 | 153 return "function"; |
154 if( type.equals("LuanJavaFunction") ) | |
155 return "function"; | |
156 return type; | |
447 | 157 } |
158 | |
1335 | 159 private Object[] fixArgs(Object[] args) throws LuanException { |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
160 int n = argConverters.length; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
161 Object[] rtn; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
162 int start = 0; |
1335 | 163 if( !takesLuan && varArgCls==null && args.length == n ) { |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
164 rtn = args; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
165 } else { |
1335 | 166 if( takesLuan ) |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
167 n++; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
168 rtn = new Object[n]; |
1335 | 169 if( takesLuan ) { |
170 rtn[start++] = luan(); | |
4
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
171 } |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
172 n = argConverters.length; |
1121
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
173 if( varArgCls == null ) { |
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
174 for( int i=n; i<args.length; i++ ) { |
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
175 if( args[i] != null ) |
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
176 throw new LuanException("too many arguments"); |
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
177 } |
4cf541886663
check for too many arguments to java fns
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
178 } else { |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
179 n--; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
180 if( args.length < argConverters.length ) { |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
181 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
|
182 } else { |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
183 int len = args.length - n; |
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
184 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
|
185 ArgConverter ac = argConverters[n]; |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
186 for( int i=0; i<len; i++ ) { |
1335 | 187 Array.set( varArgs, i, ac.convert(args[n+i]) ); |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
188 } |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
189 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
|
190 } |
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
191 } |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
192 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
|
193 } |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
194 for( int i=0; i<n; i++ ) { |
1335 | 195 rtn[start+i] = argConverters[i].convert(rtn[start+i]); |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
196 } |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
197 return rtn; |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
198 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
199 |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
200 |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
201 private interface RtnConverter { |
1335 | 202 public Object convert(Object obj); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
203 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
204 |
123
d7be9b3abf1a
minor - rename LuanFunction.EMPTY to NOTHING
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
115
diff
changeset
|
205 private static final RtnConverter RTN_NOTHING = new RtnConverter() { |
1335 | 206 @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
|
207 return NOTHING; |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
208 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
209 }; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
210 |
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
|
211 private static final RtnConverter RTN_SAME = new RtnConverter() { |
1335 | 212 @Override public Object convert(Object obj) { |
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
|
213 return obj; |
12
9cea1aea5eef
CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
4
diff
changeset
|
214 } |
9cea1aea5eef
CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
4
diff
changeset
|
215 }; |
1335 | 216 /* |
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
|
217 private static final RtnConverter RTN_ARRAY = new RtnConverter() { |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1267
diff
changeset
|
218 @Override public Object convert(Luan luan,Object obj) { |
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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 } |
1267 | 225 return new LuanTable(luan,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
|
226 } |
239c8d650028
convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
197
diff
changeset
|
227 }; |
1335 | 228 */ |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
229 private static RtnConverter getRtnConverter(JavaMethod m) { |
434 | 230 Class rtnType = m.getReturnType(); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
231 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
|
232 return RTN_NOTHING; |
1335 | 233 /* |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
234 if( !m.isLuan() && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() ) { |
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
|
235 return RTN_ARRAY; |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
236 } |
1335 | 237 */ |
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
|
238 return RTN_SAME; |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
239 } |
1259
e8020216dee7
add Luan.to_luan and fix multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1252
diff
changeset
|
240 |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
241 private interface ArgConverter { |
1335 | 242 public Object convert(Object obj) throws LuanException; |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
243 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
244 |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
245 private static final ArgConverter ARG_SAME = new ArgConverter() { |
1335 | 246 @Override public Object convert(Object obj) { |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
247 return obj; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
248 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
249 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
250 return "ARG_SAME"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
251 } |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
252 }; |
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
|
253 |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
254 private static final ArgConverter ARG_DOUBLE = new ArgConverter() { |
1335 | 255 @Override public Object convert(Object obj) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
256 if( obj instanceof Double ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
257 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
258 if( obj instanceof Number ) { |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
259 Number n = (Number)obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
260 return n.doubleValue(); |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
261 } |
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 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
264 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
265 return "ARG_DOUBLE"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
266 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
267 }; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
268 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
269 private static final ArgConverter ARG_FLOAT = new ArgConverter() { |
1335 | 270 @Override public Object convert(Object obj) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
271 if( obj instanceof Float ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
272 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
273 if( obj instanceof Number ) { |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
274 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
|
275 return n.floatValue(); |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
276 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
277 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
278 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
279 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
280 return "ARG_FLOAT"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
281 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
282 }; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
283 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
284 private static final ArgConverter ARG_LONG = new ArgConverter() { |
1335 | 285 @Override public Object convert(Object obj) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
286 if( obj instanceof Long ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
287 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
288 if( obj instanceof Number ) { |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
289 Number n = (Number)obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
290 long r = n.longValue(); |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
291 if( r==n.doubleValue() ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
292 return r; |
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_LONG"; |
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_INTEGER = new ArgConverter() { |
1335 | 302 @Override public Object convert(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 Integer ) |
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 int r = n.intValue(); |
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 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
312 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
313 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
314 return "ARG_INTEGER"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
315 } |
47
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 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
318 private static final ArgConverter ARG_SHORT = new ArgConverter() { |
1335 | 319 @Override public Object convert(Object obj) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
320 if( obj instanceof Short ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
321 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
322 if( obj instanceof Number ) { |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
323 Number n = (Number)obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
324 short r = n.shortValue(); |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
325 if( r==n.doubleValue() ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
326 return r; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
327 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
328 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
329 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
330 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
331 return "ARG_SHORT"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
332 } |
47
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 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
335 private static final ArgConverter ARG_BYTE = new ArgConverter() { |
1335 | 336 @Override public Object convert(Object obj) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
337 if( obj instanceof Byte ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
338 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
339 if( obj instanceof Number ) { |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
340 Number n = (Number)obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
341 byte r = n.byteValue(); |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
342 if( r==n.doubleValue() ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
343 return r; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
344 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
345 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
346 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
347 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
348 return "ARG_BYTE"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
349 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
350 }; |
1335 | 351 /* |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
352 private static final ArgConverter ARG_TABLE = new ArgConverter() { |
1335 | 353 @Override public Object convert(Luan luan,Object obj) { |
1267 | 354 LuanTable tbl = luan.toTable(obj); |
1259
e8020216dee7
add Luan.to_luan and fix multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1252
diff
changeset
|
355 return tbl!=null ? tbl : obj; |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
356 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
357 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
358 return "ARG_TABLE"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
359 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
360 }; |
1335 | 361 */ |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
362 private static final ArgConverter ARG_MAP = new ArgConverter() { |
1335 | 363 @Override public Object convert(Object obj) throws LuanException { |
408
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
364 if( obj instanceof LuanTable ) { |
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
365 LuanTable t = (LuanTable)obj; |
1267 | 366 return t.asMap(); |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
367 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
368 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
369 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
370 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
371 return "ARG_MAP"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
372 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
373 }; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
374 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
375 private static final ArgConverter ARG_LIST = new ArgConverter() { |
1335 | 376 @Override public Object convert(Object obj) { |
408
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
377 if( obj instanceof LuanTable ) { |
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
378 LuanTable t = (LuanTable)obj; |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
379 if( t.isList() ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
380 return t.asList(); |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
381 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
382 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
383 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
384 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
385 return "ARG_LIST"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
386 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
387 }; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
388 |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
389 private static final ArgConverter ARG_SET = new ArgConverter() { |
1335 | 390 @Override public Object convert(Object obj) throws LuanException { |
408
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
391 if( obj instanceof LuanTable ) { |
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
392 LuanTable t = (LuanTable)obj; |
1267 | 393 if( t.isSet() ) |
394 return t.asSet(); | |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
395 } |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
396 return obj; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
397 } |
244
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
398 @Override public String toString() { |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
399 return "ARG_SET"; |
0a8e6fdb62f0
fix Math.random()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
221
diff
changeset
|
400 } |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
401 }; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
402 |
396 | 403 private static final ArgConverter ARG_COLLECTION = new ArgConverter() { |
1335 | 404 @Override public Object convert(Object obj) throws LuanException { |
408
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
405 if( obj instanceof LuanTable ) { |
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
406 LuanTable t = (LuanTable)obj; |
396 | 407 if( t.isList() ) |
408 return t.asList(); | |
1267 | 409 if( t.isSet() ) |
410 return t.asSet(); | |
396 | 411 } |
412 return obj; | |
413 } | |
414 @Override public String toString() { | |
415 return "ARG_COLLECTION"; | |
416 } | |
417 }; | |
418 | |
57
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
419 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
|
420 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
|
421 |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
422 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
|
423 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
|
424 } |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
425 |
1335 | 426 @Override public Object convert(Object obj) { |
408
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
427 if( obj instanceof LuanTable ) { |
1b38de2b1845
merge LuanTableImpl into LuanTable
Franklin Schmidt <fschmidt@gmail.com>
parents:
396
diff
changeset
|
428 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
|
429 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
|
430 try { |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
431 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
|
432 } 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
|
433 } |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
434 } |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
435 return obj; |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
436 } |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
437 } |
19ca9c4c6c7f
auto-convert table to java array
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
438 |
1335 | 439 private static boolean takesLuan(JavaMethod m) { |
434 | 440 Class[] paramTypes = m.getParameterTypes(); |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1267
diff
changeset
|
441 return paramTypes.length > 0 && paramTypes[0].equals(Luan.class); |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
442 } |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
443 |
1335 | 444 private static ArgConverter[] getArgConverters(boolean takesLuan,JavaMethod m) { |
4
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
445 final boolean isVarArgs = m.isVarArgs(); |
434 | 446 Class[] paramTypes = m.getParameterTypes(); |
1335 | 447 if( takesLuan ) { |
434 | 448 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
|
449 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
|
450 paramTypes = t; |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
12
diff
changeset
|
451 } |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
452 ArgConverter[] a = new ArgConverter[paramTypes.length]; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
453 for( int i=0; i<a.length; i++ ) { |
434 | 454 Class paramType = paramTypes[i]; |
4
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
455 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
|
456 paramType = paramType.getComponentType(); |
24fd6381caca
add to interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
2
diff
changeset
|
457 a[i] = getArgConverter(paramType); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
458 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
459 return a; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
460 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
461 |
434 | 462 private static ArgConverter getArgConverter(Class cls) { |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
463 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
|
464 return ARG_DOUBLE; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
465 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
|
466 return ARG_FLOAT; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
467 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
|
468 return ARG_LONG; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
469 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
|
470 return ARG_INTEGER; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
471 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
|
472 return ARG_SHORT; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
473 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
|
474 return ARG_BYTE; |
1335 | 475 // if( cls.equals(LuanTable.class) ) |
476 // return ARG_TABLE; | |
47
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
477 if( cls.equals(Map.class) ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
478 return ARG_MAP; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
479 if( cls.equals(List.class) ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
480 return ARG_LIST; |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
481 if( cls.equals(Set.class) ) |
659c7139e903
better conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
482 return ARG_SET; |
396 | 483 if( cls.equals(Collection.class) ) |
484 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
|
485 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
|
486 return new ArgArray(cls); |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
487 return ARG_SAME; |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
488 } |
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
489 |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
490 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
491 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
492 private static abstract class JavaMethod { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
493 abstract boolean isVarArgs(); |
434 | 494 abstract Class[] getParameterTypes(); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
495 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
|
496 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException; |
434 | 497 abstract Class getReturnType(); |
1335 | 498 abstract String getName(); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
499 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
500 static JavaMethod of(final Method m) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
501 return new JavaMethod() { |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
502 @Override boolean isVarArgs() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
503 return m.isVarArgs(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
504 } |
434 | 505 @Override Class[] getParameterTypes() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
506 return m.getParameterTypes(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
507 } |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
508 @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
|
509 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
510 { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
511 return m.invoke(obj,args); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
512 } |
434 | 513 @Override Class getReturnType() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
514 return m.getReturnType(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
515 } |
1335 | 516 @Override public String getName() { |
517 return m.getName(); | |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
518 } |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
519 @Override public String toString() { |
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
520 return m.toString(); |
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
521 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
522 }; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
523 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
524 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
525 static JavaMethod of(final Constructor c) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
526 return new JavaMethod() { |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
527 @Override boolean isVarArgs() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
528 return c.isVarArgs(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
529 } |
434 | 530 @Override Class[] getParameterTypes() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
531 return c.getParameterTypes(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
532 } |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
533 @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
|
534 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
535 { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
536 return c.newInstance(args); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
537 } |
434 | 538 @Override Class getReturnType() { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
539 return c.getDeclaringClass(); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
540 } |
1335 | 541 @Override public String getName() { |
542 return c.getName(); | |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
249
diff
changeset
|
543 } |
43
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
544 @Override public String toString() { |
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
545 return c.toString(); |
80b67b1a653c
implement string lib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
40
diff
changeset
|
546 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
547 }; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
548 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
21
diff
changeset
|
549 |
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 |
1
2df768b926aa
start Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
552 } |