Mercurial Hosting > luan
comparison core/src/luan/modules/PackageLuan.java @ 297:899253043270
remove PackageLuan.load_lib()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@298 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 16 Dec 2014 03:26:43 +0000 |
parents | 7ea6dfdf81ba |
children | a74559240b4f |
comparison
equal
deleted
inserted
replaced
296:7ea6dfdf81ba | 297:899253043270 |
---|---|
13 import luan.LuanException; | 13 import luan.LuanException; |
14 | 14 |
15 | 15 |
16 public final class PackageLuan { | 16 public final class PackageLuan { |
17 | 17 |
18 public static final LuanFunction LOADER = new LuanFunction() { | |
19 @Override public Object call(LuanState luan,Object[] args) { | |
20 LuanTable module = Luan.newTable(); | |
21 module.put( "loaded", loaded(luan) ); | |
22 try { | |
23 module.put("require",requireFn); | |
24 add( module, "load", LuanState.class, String.class ); | |
25 // add( module, "load_lib", LuanState.class, String.class ); | |
26 add( module, "search", LuanState.class, String.class ); | |
27 } catch(NoSuchMethodException e) { | |
28 throw new RuntimeException(e); | |
29 } | |
30 return module; | |
31 } | |
32 }; | |
33 | |
34 public static final LuanFunction requireFn; | 18 public static final LuanFunction requireFn; |
35 static { | 19 static { |
36 try { | 20 try { |
37 requireFn = new LuanJavaFunction(PackageLuan.class.getMethod("require",LuanState.class,String.class),null); | 21 requireFn = new LuanJavaFunction(PackageLuan.class.getMethod("require",LuanState.class,String.class),null); |
38 } catch(NoSuchMethodException e) { | 22 } catch(NoSuchMethodException e) { |
39 throw new RuntimeException(e); | 23 throw new RuntimeException(e); |
40 } | 24 } |
41 } | |
42 | |
43 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | |
44 t.put( method, new LuanJavaFunction(PackageLuan.class.getMethod(method,parameterTypes),null) ); | |
45 } | 25 } |
46 | 26 |
47 public static LuanTable loaded(LuanState luan) { | 27 public static LuanTable loaded(LuanState luan) { |
48 return luan.registryTable("Package.loaded"); | 28 return luan.registryTable("Package.loaded"); |
49 } | 29 } |
96 public static Object[] search(LuanState luan,String modName) throws LuanException { | 76 public static Object[] search(LuanState luan,String modName) throws LuanException { |
97 LuanFunction fn = loader(luan,modName,true,null); | 77 LuanFunction fn = loader(luan,modName,true,null); |
98 return fn==null ? null : new Object[]{fn,modName}; | 78 return fn==null ? null : new Object[]{fn,modName}; |
99 } | 79 } |
100 | 80 |
101 | |
102 static LuanFunction load_lib(LuanState luan,String path) | |
103 throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException | |
104 { | |
105 int i = path.lastIndexOf('.'); | |
106 String clsPath = path.substring(0,i); | |
107 String fld = path.substring(i+1); | |
108 Class cls = Class.forName(clsPath); | |
109 return (LuanFunction)cls.getField(fld).get(null); | |
110 } | |
111 | |
112 } | 81 } |