comparison src/luan/lib/StringLib.java @ 108:3c404a296995

make Package module more standard; return _ENV by default; add "import" statement; git-svn-id: https://luan-java.googlecode.com/svn/trunk@109 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 May 2014 03:21:54 +0000
parents b1e87f1bcc13
children f5af13062b10
comparison
equal deleted inserted replaced
107:dbf459397217 108:3c404a296995
4 import java.util.regex.Matcher; 4 import java.util.regex.Matcher;
5 import luan.Luan; 5 import luan.Luan;
6 import luan.LuanState; 6 import luan.LuanState;
7 import luan.LuanTable; 7 import luan.LuanTable;
8 import luan.LuanFunction; 8 import luan.LuanFunction;
9 import luan.LuanLoader;
10 import luan.LuanJavaFunction; 9 import luan.LuanJavaFunction;
11 import luan.LuanElement; 10 import luan.LuanElement;
12 import luan.LuanException; 11 import luan.LuanException;
13 12
14 13
15 public final class StringLib { 14 public final class StringLib {
16 15
17 public static final String NAME = "String"; 16 public static final String NAME = "String";
18 17
19 public static final LuanLoader LOADER = new LuanLoader() { 18 public static final LuanFunction LOADER = new LuanFunction() {
20 @Override protected void load(LuanState luan) { 19 @Override public Object[] call(LuanState luan,Object[] args) {
21 LuanTable module = new LuanTable(); 20 LuanTable module = new LuanTable();
22 try { 21 try {
23 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) ); 22 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) );
24 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) ); 23 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) );
25 add( module, "find", String.class, String.class, Integer.class, Boolean.class ); 24 add( module, "find", String.class, String.class, Integer.class, Boolean.class );
34 add( module, "sub", String.class, Integer.TYPE, Integer.class ); 33 add( module, "sub", String.class, Integer.TYPE, Integer.class );
35 add( module, "upper", String.class ); 34 add( module, "upper", String.class );
36 } catch(NoSuchMethodException e) { 35 } catch(NoSuchMethodException e) {
37 throw new RuntimeException(e); 36 throw new RuntimeException(e);
38 } 37 }
39 luan.loaded().put(NAME,module); 38 return new Object[]{module};
40 } 39 }
41 }; 40 };
42 41
43 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { 42 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
44 t.put( method, new LuanJavaFunction(StringLib.class.getMethod(method,parameterTypes),null) ); 43 t.put( method, new LuanJavaFunction(StringLib.class.getMethod(method,parameterTypes),null) );