comparison src/luan/lib/StringLib.java @ 73:f86e4f77ef32

add package module git-svn-id: https://luan-java.googlecode.com/svn/trunk@74 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 12 Feb 2013 09:46:45 +0000
parents 8ede219cd111
children f003338d503b
comparison
equal deleted inserted replaced
72:cd9dbd7477ca 73:f86e4f77ef32
11 import luan.LuanException; 11 import luan.LuanException;
12 12
13 13
14 public final class StringLib { 14 public final class StringLib {
15 15
16 public static void register(LuanState luan) { 16 public static final String NAME = "string";
17 LuanTable module = new LuanTable(); 17
18 LuanTable global = luan.global(); 18 public static final LuanFunction LOADER = new LuanFunction() {
19 global.put("string",module); 19 public Object[] call(LuanState luan,Object[] args) throws LuanException {
20 try { 20 LuanTable module = new LuanTable();
21 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) ); 21 LuanTable global = luan.global;
22 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) ); 22 global.put(NAME,module);
23 add( module, "find", String.class, String.class, Integer.class, Boolean.class ); 23 try {
24 add( module, "gmatch", String.class, String.class ); 24 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) );
25 add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class ); 25 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) );
26 add( module, "len", String.class ); 26 add( module, "find", String.class, String.class, Integer.class, Boolean.class );
27 add( module, "lower", String.class ); 27 add( module, "gmatch", String.class, String.class );
28 add( module, "match", String.class, String.class, Integer.class ); 28 add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class );
29 add( module, "rep", String.class, Integer.TYPE, String.class ); 29 add( module, "len", String.class );
30 add( module, "reverse", String.class ); 30 add( module, "lower", String.class );
31 add( module, "sub", String.class, Integer.TYPE, Integer.class ); 31 add( module, "match", String.class, String.class, Integer.class );
32 add( module, "upper", String.class ); 32 add( module, "rep", String.class, Integer.TYPE, String.class );
33 } catch(NoSuchMethodException e) { 33 add( module, "reverse", String.class );
34 throw new RuntimeException(e); 34 add( module, "sub", String.class, Integer.TYPE, Integer.class );
35 } 35 add( module, "upper", String.class );
36 } 36 } catch(NoSuchMethodException e) {
37 throw new RuntimeException(e);
38 }
39 return LuanFunction.EMPTY_RTN;
40 }
41 };
37 42
38 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { 43 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
39 t.put( method, new LuanJavaFunction(StringLib.class.getMethod(method,parameterTypes),null) ); 44 t.put( method, new LuanJavaFunction(StringLib.class.getMethod(method,parameterTypes),null) );
40 } 45 }
41 46