comparison core/src/luan/modules/ThreadLuan.java @ 301:a6bf8ff720f8

add java security git-svn-id: https://luan-java.googlecode.com/svn/trunk@302 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 17 Dec 2014 12:35:57 +0000
parents ec016471c6eb
children c6bcb8859b93
comparison
equal deleted inserted replaced
300:9fb523472035 301:a6bf8ff720f8
4 import java.util.concurrent.Executors; 4 import java.util.concurrent.Executors;
5 import luan.Luan; 5 import luan.Luan;
6 import luan.LuanState; 6 import luan.LuanState;
7 import luan.LuanFunction; 7 import luan.LuanFunction;
8 import luan.LuanTable; 8 import luan.LuanTable;
9 import luan.LuanJavaFunction;
10 import luan.LuanException; 9 import luan.LuanException;
11 import luan.DeepCloner; 10 import luan.DeepCloner;
12 11
13 12
14 public final class ThreadLuan { 13 public final class ThreadLuan {
15
16 public static final LuanFunction LOADER = new LuanFunction() {
17 @Override public Object call(LuanState luan,Object[] args) {
18 LuanTable module = Luan.newTable();
19 try {
20 add( module, "fork", LuanState.class, LuanFunction.class, new Object[0].getClass() );
21 } catch(NoSuchMethodException e) {
22 throw new RuntimeException(e);
23 }
24 return module;
25 }
26 };
27
28 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
29 t.put( method, new LuanJavaFunction(ThreadLuan.class.getMethod(method,parameterTypes),null) );
30 }
31
32 private static final Executor exec = Executors.newCachedThreadPool(); 14 private static final Executor exec = Executors.newCachedThreadPool();
33 15
34 public static void fork(LuanState luan,LuanFunction fn,Object... args) { 16 public static void fork(LuanState luan,LuanFunction fn,Object... args) {
35 DeepCloner cloner = new DeepCloner(); 17 DeepCloner cloner = new DeepCloner();
36 final LuanState newLuan = cloner.deepClone(luan); 18 final LuanState newLuan = cloner.deepClone(luan);
42 } catch(LuanException e) { 24 } catch(LuanException e) {
43 e.printStackTrace(); 25 e.printStackTrace();
44 } 26 }
45 }}); 27 }});
46 } 28 }
47
48 } 29 }