Mercurial Hosting > luan
annotate core/src/luan/modules/JavaLuan.java @ 320:fed1893821bf
remove global namespace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@321 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 06 Feb 2015 21:54:41 +0000 |
parents | 03e9cda4748d |
children | 7f7708e8fdd4 |
rev | line source |
---|---|
167
4c0131c2b650
merge luan/lib into modules
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
163
diff
changeset
|
1 package luan.modules; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
3 import java.lang.reflect.Array; |
50
272b6f1d7dac
fix java accessibility
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
49
diff
changeset
|
4 import java.lang.reflect.AccessibleObject; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5 import java.lang.reflect.Member; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6 import java.lang.reflect.Field; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7 import java.lang.reflect.Method; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
8 import java.lang.reflect.Constructor; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9 import java.lang.reflect.Modifier; |
61
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
10 import java.lang.reflect.InvocationHandler; |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
11 import java.lang.reflect.Proxy; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
12 import java.util.Map; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
13 import java.util.HashMap; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
14 import java.util.List; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
15 import java.util.ArrayList; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 import java.util.Iterator; |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
51
diff
changeset
|
17 import java.util.Collections; |
157
1de3e4a6e82d
remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
142
diff
changeset
|
18 import java.util.Arrays; |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
19 import luan.Luan; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
20 import luan.LuanState; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
21 import luan.LuanTable; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
22 import luan.LuanException; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
23 import luan.LuanFunction; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
24 import luan.LuanJavaFunction; |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
25 import luan.LuanElement; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
26 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
27 |
168
ebe9db183eb7
rename *Lib.java to *Luan.java
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
167
diff
changeset
|
28 public final class JavaLuan { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
29 |
301
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
30 public static void java(LuanState luan) throws LuanException { |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
31 check(luan,luan.currentSource().name); |
300
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
32 luan.currentEnvironment().setJava(); |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
33 } |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
34 |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
35 private static void checkJava(LuanState luan) throws LuanException { |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
36 if( !luan.currentEnvironment().hasJava() ) |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
37 throw luan.exception("Java isn't allowed"); |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
38 } |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
39 |
202
75750ceb45ee
add LuanState.registry
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
197
diff
changeset
|
40 private static boolean isLoaded(LuanState luan) { |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
277
diff
changeset
|
41 // return PackageLuan.loaded(luan).get("luan:Java") != null; |
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
277
diff
changeset
|
42 return true; |
202
75750ceb45ee
add LuanState.registry
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
197
diff
changeset
|
43 } |
75750ceb45ee
add LuanState.registry
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
197
diff
changeset
|
44 |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
45 public static Object __index(LuanState luan,Object obj,Object key) throws LuanException { |
300
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
46 if( !luan.currentEnvironment().hasJava() ) |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
47 return null; |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
48 if( obj instanceof Static ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
49 if( key instanceof String ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
50 String name = (String)key; |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
51 Static st = (Static)obj; |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
52 Class cls = st.cls; |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
53 if( "class".equals(name) ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
54 return cls; |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
55 } else if( "new".equals(name) ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
56 Constructor<?>[] constructors = cls.getConstructors(); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
57 if( constructors.length > 0 ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
58 if( constructors.length==1 ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
59 return new LuanJavaFunction(constructors[0],null); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
60 } else { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
61 List<LuanJavaFunction> fns = new ArrayList<LuanJavaFunction>(); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
62 for( Constructor constructor : constructors ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
63 fns.add(new LuanJavaFunction(constructor,null)); |
197
4c96cb73dd93
fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
196
diff
changeset
|
64 } |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
65 return new AmbiguousJavaFunction(fns); |
197
4c96cb73dd93
fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
196
diff
changeset
|
66 } |
4c96cb73dd93
fix metatable cloning
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
196
diff
changeset
|
67 } |
304
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
68 /* |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
69 } else if( "assert".equals(name) ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
70 return new LuanJavaFunction(assertClass,new AssertClass(cls)); |
304
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
71 */ |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
72 } else if( "luan_proxy".equals(name) ) { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
73 return new LuanJavaFunction(luan_proxyMethod,st); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
74 } else { |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
75 List<Member> members = getStaticMembers(cls,name); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
76 if( !members.isEmpty() ) { |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
77 return member(null,members); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
78 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
79 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
80 } |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
81 throw luan.exception("invalid member '"+key+"' for: "+obj); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
82 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
83 Class cls = obj.getClass(); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
84 if( cls.isArray() ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
85 if( "length".equals(key) ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
86 return Array.getLength(obj); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
87 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
88 Integer i = Luan.asInteger(key); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
89 if( i != null ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
90 return Array.get(obj,i); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
91 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
92 throw luan.exception("invalid member '"+key+"' for java array: "+obj); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
93 } |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
94 if( key instanceof String ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
95 String name = (String)key; |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
96 if( "instanceof".equals(name) ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
97 return new LuanJavaFunction(instanceOf,new InstanceOf(obj)); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
98 } else { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
99 List<Member> members = getMembers(cls,name); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
100 if( !members.isEmpty() ) { |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
101 return member(obj,members); |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
102 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
103 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
104 } |
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
105 // throw luan.exception("invalid member '"+key+"' for java object: "+obj); |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
277
diff
changeset
|
106 //System.out.println("invalid member '"+key+"' for java object: "+obj); |
208
5ba136769034
remove MetatableGetter and use a generic metatable instead
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
202
diff
changeset
|
107 return null; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
108 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
109 |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
110 private static Object member(Object obj,List<Member> members) throws LuanException { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
111 try { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
112 if( members.size()==1 ) { |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
113 Member member = members.get(0); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
114 if( member instanceof Static ) { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
115 return member; |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
116 } else if( member instanceof Field ) { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
117 Field field = (Field)member; |
157
1de3e4a6e82d
remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
142
diff
changeset
|
118 Object rtn = field.get(obj); |
1de3e4a6e82d
remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
142
diff
changeset
|
119 return rtn instanceof Object[] ? Arrays.asList((Object[])rtn) : rtn; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
120 } else { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
121 Method method = (Method)member; |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
277
diff
changeset
|
122 return new LuanJavaFunction(method,obj); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
123 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
124 } else { |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
125 List<LuanJavaFunction> fns = new ArrayList<LuanJavaFunction>(); |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
126 for( Member member : members ) { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
127 Method method = (Method)member; |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
277
diff
changeset
|
128 fns.add(new LuanJavaFunction(method,obj)); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
129 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
130 return new AmbiguousJavaFunction(fns); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
131 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
132 } catch(IllegalAccessException e) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
133 throw new RuntimeException(e); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
134 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
135 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
136 |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
137 public static void __newindex(LuanState luan,Object obj,Object key,Object value) throws LuanException { |
300
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
138 checkJava(luan); |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
139 if( obj instanceof Static ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
140 if( key instanceof String ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
141 String name = (String)key; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
142 Static st = (Static)obj; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
143 Class cls = st.cls; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
144 List<Member> members = getStaticMembers(cls,name); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
145 if( !members.isEmpty() ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
146 if( members.size() != 1 ) |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
147 throw new RuntimeException("not field '"+name+"' of "+obj); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
148 setMember(obj,members,value); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
149 return; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
150 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
151 } |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
152 throw luan.exception("invalid member '"+key+"' for: "+obj); |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
153 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
154 Class cls = obj.getClass(); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
155 if( cls.isArray() ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
156 Integer i = Luan.asInteger(key); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
157 if( i != null ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
158 Array.set(obj,i,value); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
159 return; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
160 } |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
161 throw luan.exception("invalid member '"+key+"' for java array: "+obj); |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
162 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
163 if( key instanceof String ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
164 String name = (String)key; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
165 List<Member> members = getMembers(cls,name); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
166 if( !members.isEmpty() ) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
167 if( members.size() != 1 ) |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
168 throw new RuntimeException("not field '"+name+"' of "+obj); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
169 setMember(obj,members,value); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
170 return; |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
171 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
172 } |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
173 throw luan.exception("invalid member '"+key+"' for java object: "+obj); |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
174 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
175 |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
176 private static void setMember(Object obj,List<Member> members,Object value) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
177 Field field = (Field)members.get(0); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
178 try { |
100
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
179 try { |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
180 field.set(obj,value); |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
181 } catch(IllegalArgumentException e) { |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
182 Class cls = field.getType(); |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
183 if( value instanceof Number ) { |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
184 Number n = (Number)value; |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
185 if( cls.equals(Integer.TYPE) || cls.equals(Integer.class) ) { |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
186 int r = n.intValue(); |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
187 if( r==n.doubleValue() ) { |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
188 field.setInt(obj,r); |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
189 return; |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
190 } |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
191 } |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
192 } |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
193 throw e; |
6c827f7275df
fix JavaLib.setMember() for int conversion
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
90
diff
changeset
|
194 } |
60
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
195 } catch(IllegalAccessException e) { |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
196 throw new RuntimeException(e); |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
197 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
198 } |
a68ccb7aaa9c
implement setting java field values
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
58
diff
changeset
|
199 |
102
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
200 public static boolean privateAccess = false; |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
201 private static Map<Class,Map<String,List<Member>>> memberMap = new HashMap<Class,Map<String,List<Member>>>(); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
202 |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
203 private static synchronized List<Member> getMembers(Class cls,String name) { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
204 Map<String,List<Member>> clsMap = memberMap.get(cls); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
205 if( clsMap == null ) { |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
206 clsMap = new HashMap<String,List<Member>>(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
207 for( Class c : cls.getClasses() ) { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
208 String s = c.getSimpleName(); |
71
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
209 List<Member> list = new ArrayList<Member>(); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
210 clsMap.put(s,list); |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
211 list.add(new Static(c)); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
212 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
213 for( Field field : cls.getFields() ) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
214 String s = field.getName(); |
58
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
215 try { |
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
216 if( !cls.getField(s).equals(field) ) |
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
217 continue; // not accessible |
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
218 } catch(NoSuchFieldException e) { |
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
219 throw new RuntimeException(e); |
d6c454b7f58c
make concat work with any type;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
56
diff
changeset
|
220 } |
71
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
221 List<Member> list = new ArrayList<Member>(); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
222 clsMap.put(s,list); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
223 list.add(field); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
224 } |
71
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
225 for( Method method : cls.getMethods() ) { |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
226 String s = method.getName(); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
227 List<Member> list = clsMap.get(s); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
228 if( list == null || !(list.get(0) instanceof Method) ) { |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
229 list = new ArrayList<Member>(); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
230 clsMap.put(s,list); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
231 } |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
232 list.add(method); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
233 } |
102
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
234 if( privateAccess ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
235 for( Method method : cls.getDeclaredMethods() ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
236 String s = method.getName(); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
237 List<Member> list = clsMap.get(s); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
238 if( list == null ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
239 list = new ArrayList<Member>(); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
240 clsMap.put(s,list); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
241 } else if( !(list.get(0) instanceof Method) ) |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
242 continue; |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
243 if( !list.contains(method) ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
244 list.add(method); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
245 } |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
246 } |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
247 for( Field field : cls.getDeclaredFields() ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
248 String s = field.getName(); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
249 List<Member> list = clsMap.get(s); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
250 if( list == null ) { |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
251 list = new ArrayList<Member>(); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
252 clsMap.put(s,list); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
253 list.add(field); |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
254 } |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
255 } |
90b918cbf888
add JavaLib.privateAccess
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
100
diff
changeset
|
256 } |
71
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
257 for( List<Member> members : clsMap.values() ) { |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
258 for( Member m : members ) { |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
259 if( m instanceof AccessibleObject ) |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
260 ((AccessibleObject)m).setAccessible(true); |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
261 } |
5a93129995e1
handle conflicting java member names
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
64
diff
changeset
|
262 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
263 memberMap.put(cls,clsMap); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
264 } |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
265 List<Member> rtn = clsMap.get(name); |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
51
diff
changeset
|
266 if( rtn==null ) |
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
51
diff
changeset
|
267 rtn = Collections.emptyList(); |
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
51
diff
changeset
|
268 return rtn; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
269 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
270 |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
271 private static synchronized List<Member> getStaticMembers(Class cls,String name) { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
272 List<Member> staticMembers = new ArrayList<Member>(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
273 for( Member m : getMembers(cls,name) ) { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
274 if( Modifier.isStatic(m.getModifiers()) ) |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
275 staticMembers.add(m); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
276 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
277 return staticMembers; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
278 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
279 |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
280 static final class Static implements Member { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
281 final Class cls; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
282 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
283 Static(Class cls) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
284 this.cls = cls; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
285 } |
56
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
286 |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
287 @Override public String toString() { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
288 return cls.toString(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
289 } |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
290 |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
291 @Override public Class<?> getDeclaringClass() { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
292 return cls.getDeclaringClass(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
293 } |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
294 |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
295 @Override public String getName() { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
296 return cls.getName(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
297 } |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
298 |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
299 @Override public int getModifiers() { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
300 return cls.getModifiers(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
301 } |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
302 |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
303 @Override public boolean isSynthetic() { |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
304 return cls.isSynthetic(); |
c84274b18f0c
various
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
55
diff
changeset
|
305 } |
304
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
306 |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
307 public Object luan_proxy(final LuanState luan,final LuanTable t,final Object base) throws LuanException { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
308 return Proxy.newProxyInstance( |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
309 cls.getClassLoader(), |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
310 new Class[]{cls}, |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
311 new InvocationHandler() { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
312 public Object invoke(Object proxy,Method method, Object[] args) |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
313 throws Throwable |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
314 { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
315 if( args==null ) |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
316 args = new Object[0]; |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
317 String name = method.getName(); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
318 Object fnObj = t.get(name); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
319 if( fnObj==null && base!=null ) |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
320 return method.invoke(base,args); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
321 LuanFunction fn = luan.checkFunction(fnObj); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
322 return Luan.first(luan.call(fn,name,args)); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
323 } |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
324 } |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
325 ); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
326 } |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
327 } |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
328 private static final Method luan_proxyMethod; |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
329 static { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
330 try { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
331 luan_proxyMethod = Static.class.getMethod("luan_proxy",LuanState.class,LuanTable.class,Object.class); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
332 luan_proxyMethod.setAccessible(true); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
333 } catch(NoSuchMethodException e) { |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
334 throw new RuntimeException(e); |
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
335 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
336 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
337 |
299
a74559240b4f
simplify PackageLuan and remove IO loading param
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
338 public static Static load(LuanState luan,String name) throws LuanException { |
300
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
339 checkJava(luan); |
51
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
340 Class cls; |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
341 try { |
51
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
342 cls = Class.forName(name); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
343 } catch(ClassNotFoundException e) { |
51
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
344 try { |
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
345 cls = Thread.currentThread().getContextClassLoader().loadClass(name); |
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
346 } catch(ClassNotFoundException e2) { |
108
3c404a296995
make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
102
diff
changeset
|
347 return null; |
51
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
348 } |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
349 } |
51
28dfd91a816c
various small issues
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
50
diff
changeset
|
350 return new Static(cls); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
351 } |
300
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
352 |
9fb523472035
add java() to control java access
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
299
diff
changeset
|
353 private static class AmbiguousJavaFunction extends LuanFunction { |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
354 private final Map<Integer,List<LuanJavaFunction>> fnMap = new HashMap<Integer,List<LuanJavaFunction>>(); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
355 |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
356 AmbiguousJavaFunction(List<LuanJavaFunction> fns) { |
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
357 for( LuanJavaFunction fn : fns ) { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
358 Integer n = fn.getParameterTypes().length; |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
359 List<LuanJavaFunction> list = fnMap.get(n); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
360 if( list==null ) { |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
361 list = new ArrayList<LuanJavaFunction>(); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
362 fnMap.put(n,list); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
363 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
364 list.add(fn); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
365 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
366 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
367 |
112
f5af13062b10
fix previous rev
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
108
diff
changeset
|
368 @Override public Object call(LuanState luan,Object[] args) throws LuanException { |
48
64ecb7a3aad7
rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
46
diff
changeset
|
369 for( LuanJavaFunction fn : fnMap.get(args.length) ) { |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
370 try { |
55
9381b23ea9e1
various fixes
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
51
diff
changeset
|
371 return fn.rawCall(luan,args); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
372 } catch(IllegalArgumentException e) {} |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
373 } |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
374 throw luan.exception("no method matched args"); |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
375 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
376 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
377 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
378 private static class InstanceOf { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
379 private final Object obj; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
380 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
381 InstanceOf(Object obj) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
382 this.obj = obj; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
383 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
384 |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
385 public boolean instanceOf(Static st) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
386 return st.cls.isInstance(obj); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
387 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
388 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
389 private static final Method instanceOf; |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
390 static { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
391 try { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
392 instanceOf = InstanceOf.class.getMethod("instanceOf",Static.class); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
393 instanceOf.setAccessible(true); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
394 } catch(NoSuchMethodException e) { |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
395 throw new RuntimeException(e); |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
396 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
397 } |
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
398 |
304
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
399 /* |
64
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
400 private static class AssertClass { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
401 private final Class cls; |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
402 |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
403 AssertClass(Class cls) { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
404 this.cls = cls; |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
405 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
406 |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
407 public Object assertClass(LuanState luan,Object v) throws LuanException { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
408 if( !cls.isInstance(v) ) { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
409 String got = v.getClass().getSimpleName(); |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
410 String expected = cls.getSimpleName(); |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
411 throw luan.exception("bad argument #1 ("+expected+" expected, got "+got+")"); |
64
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
412 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
413 return v; |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
414 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
415 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
416 private static final Method assertClass; |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
417 static { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
418 try { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
419 assertClass = AssertClass.class.getMethod("assertClass",LuanState.class,Object.class); |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
420 assertClass.setAccessible(true); |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
421 } catch(NoSuchMethodException e) { |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
422 throw new RuntimeException(e); |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
423 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
424 } |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
425 |
177cfdc2bdb3
add type assertions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
63
diff
changeset
|
426 |
62
7c05f53ef6cb
improve java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
61
diff
changeset
|
427 public static Object proxy(final LuanState luan,Static st,final LuanTable t,final Object base) throws LuanException { |
61
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
428 return Proxy.newProxyInstance( |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
429 st.cls.getClassLoader(), |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
430 new Class[]{st.cls}, |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
431 new InvocationHandler() { |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
432 public Object invoke(Object proxy,Method method, Object[] args) |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
433 throws Throwable |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
434 { |
63
ebe578282363
minor fix
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
62
diff
changeset
|
435 if( args==null ) |
ebe578282363
minor fix
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
62
diff
changeset
|
436 args = new Object[0]; |
61
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
437 String name = method.getName(); |
62
7c05f53ef6cb
improve java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
61
diff
changeset
|
438 Object fnObj = t.get(name); |
7c05f53ef6cb
improve java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
61
diff
changeset
|
439 if( fnObj==null && base!=null ) |
7c05f53ef6cb
improve java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
61
diff
changeset
|
440 return method.invoke(base,args); |
130
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
441 LuanFunction fn = luan.checkFunction(fnObj); |
0594c132888b
cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
124
diff
changeset
|
442 return Luan.first(luan.call(fn,name,args)); |
61
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
443 } |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
444 } |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
445 ); |
183d470be7e8
add java.proxy
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
60
diff
changeset
|
446 } |
304
03e9cda4748d
add JavaLuan.Static.luan_proxy()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
301
diff
changeset
|
447 */ |
301
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
448 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
449 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
450 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
451 // security |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
452 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
453 public interface Security { |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
454 public void check(LuanState luan,String name) throws LuanException; |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
455 } |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
456 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
457 private static String SECURITY_KEY = "Java.Security"; |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
458 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
459 private static void check(LuanState luan,String name) throws LuanException { |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
460 Security s = (Security)luan.registry().get(SECURITY_KEY); |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
461 if( s!=null ) |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
462 s.check(luan,name); |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
463 } |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
464 |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
465 public static void setSecurity(LuanState luan,Security s) { |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
466 luan.registry().put(SECURITY_KEY,s); |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
467 } |
a6bf8ff720f8
add java security
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
300
diff
changeset
|
468 |
37
8a57ebfdfd78
add JavaLib
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
469 } |