diff 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
line wrap: on
line diff
--- a/src/luan/lib/StringLib.java	Tue Feb 12 05:44:15 2013 +0000
+++ b/src/luan/lib/StringLib.java	Tue Feb 12 09:46:45 2013 +0000
@@ -13,27 +13,32 @@
 
 public final class StringLib {
 
-	public static void register(LuanState luan) {
-		LuanTable module = new LuanTable();
-		LuanTable global = luan.global();
-		global.put("string",module);
-		try {
-			module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) );
-			module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) );
-			add( module, "find", String.class, String.class, Integer.class, Boolean.class );
-			add( module, "gmatch", String.class, String.class );
-			add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class );
-			add( module, "len", String.class );
-			add( module, "lower", String.class );
-			add( module, "match", String.class, String.class, Integer.class );
-			add( module, "rep", String.class, Integer.TYPE, String.class );
-			add( module, "reverse", String.class );
-			add( module, "sub", String.class, Integer.TYPE, Integer.class );
-			add( module, "upper", String.class );
-		} catch(NoSuchMethodException e) {
-			throw new RuntimeException(e);
+	public static final String NAME = "string";
+
+	public static final LuanFunction LOADER = new LuanFunction() {
+		public Object[] call(LuanState luan,Object[] args) throws LuanException {
+			LuanTable module = new LuanTable();
+			LuanTable global = luan.global;
+			global.put(NAME,module);
+			try {
+				module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) );
+				module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) );
+				add( module, "find", String.class, String.class, Integer.class, Boolean.class );
+				add( module, "gmatch", String.class, String.class );
+				add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class );
+				add( module, "len", String.class );
+				add( module, "lower", String.class );
+				add( module, "match", String.class, String.class, Integer.class );
+				add( module, "rep", String.class, Integer.TYPE, String.class );
+				add( module, "reverse", String.class );
+				add( module, "sub", String.class, Integer.TYPE, Integer.class );
+				add( module, "upper", String.class );
+			} catch(NoSuchMethodException e) {
+				throw new RuntimeException(e);
+			}
+			return LuanFunction.EMPTY_RTN;
 		}
-	}
+	};
 
 	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
 		t.put( method, new LuanJavaFunction(StringLib.class.getMethod(method,parameterTypes),null) );