changeset 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 2ce23c7e2342
files core/src/luan/LuanJavaFunction.java core/src/luan/LuanMethod.java core/src/luan/modules/Basic.luan core/src/luan/modules/BasicLuan.java core/src/luan/modules/Io.luan core/src/luan/modules/IoLuan.java core/src/luan/modules/JavaLuan.java core/src/luan/modules/Math.luan core/src/luan/modules/MathLuan.java core/src/luan/modules/Package.luan core/src/luan/modules/PackageLuan.java core/src/luan/modules/String.luan core/src/luan/modules/StringLuan.java core/src/luan/modules/Table.luan core/src/luan/modules/TableLuan.java core/src/luan/modules/Time.luan logging/src/luan/modules/logging/Logging.luan lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneSearcher.java mail/src/luan/modules/mail/Mail.luan web/src/luan/modules/web/Http.luan web/src/luan/modules/web/Web_server.luan
diffstat 22 files changed, 141 insertions(+), 258 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanJavaFunction.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/LuanJavaFunction.java	Tue Dec 16 03:26:43 2014 +0000
@@ -21,21 +21,17 @@
 	private final Class<?> varArgCls;
 
 	public LuanJavaFunction(Method method,Object obj) {
-		this(method,obj,false);
-	}
-
-	public LuanJavaFunction(Method method,Object obj,boolean convertArray) {
-		this( JavaMethod.of(method), obj, convertArray );
+		this( JavaMethod.of(method), obj );
 	}
 
 	public LuanJavaFunction(Constructor constr,Object obj) {
-		this( JavaMethod.of(constr), obj, false );
+		this( JavaMethod.of(constr), obj );
 	}
 
-	private LuanJavaFunction(JavaMethod method,Object obj,boolean convertArray) {
+	private LuanJavaFunction(JavaMethod method,Object obj) {
 		this.method = method;
 		this.obj = obj;
-		this.rtnConverter = getRtnConverter(method,convertArray);
+		this.rtnConverter = getRtnConverter(method);
 		this.takesLuaState = takesLuaState(method);
 		this.argConverters = getArgConverters(takesLuaState,method);
 		if( method.isVarArgs() ) {
@@ -208,12 +204,14 @@
 		}
 	};
 
-	private static RtnConverter getRtnConverter(JavaMethod m,boolean convertArray) {
+	private static RtnConverter getRtnConverter(JavaMethod m) {
 		Class<?> rtnType = m.getReturnType();
 		if( rtnType == Void.TYPE )
 			return RTN_NOTHING;
-		if( convertArray && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() )
+		if( !m.isLuan() && rtnType.isArray() && !rtnType.getComponentType().isPrimitive() ) {
+//System.out.println("qqqqqq "+m);
 			return RTN_ARRAY;
+		}
 		return RTN_SAME;
 	}
 
@@ -544,6 +542,7 @@
 		abstract Object invoke(Object obj,Object... args)
 			throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException;
 		abstract Class<?> getReturnType();
+		abstract boolean isLuan();
 	
 		static JavaMethod of(final Method m) {
 			return new JavaMethod() {
@@ -561,6 +560,9 @@
 				@Override Class<?> getReturnType() {
 					return m.getReturnType();
 				}
+				@Override boolean isLuan() {
+					return m.getAnnotation(LuanMethod.class) != null;
+				}
 				@Override public String toString() {
 					return m.toString();
 				}
@@ -583,6 +585,9 @@
 				@Override Class<?> getReturnType() {
 					return c.getDeclaringClass();
 				}
+				@Override boolean isLuan() {
+					return false;
+				}
 				@Override public String toString() {
 					return c.toString();
 				}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/LuanMethod.java	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,8 @@
+package luan;
+
+import java.lang.annotation.*;
+
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface LuanMethod {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Basic.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,29 @@
+import "java:luan.modules.BasicLuan"
+
+assert = BasicLuan.assert_
+assert_boolean = BasicLuan.assert_boolean
+assert_nil = BasicLuan.assert_nil
+assert_number = BasicLuan.assert_number
+assert_string = BasicLuan.assert_string
+assert_table = BasicLuan.assert_table
+assert_integer = BasicLuan.assert_integer
+assert_long = BasicLuan.assert_long
+do_file = BasicLuan.do_file
+error = BasicLuan.error
+get_metatable = BasicLuan.get_metatable
+ipairs = BasicLuan.ipairs
+load = BasicLuan.load
+load_file = BasicLuan.load_file
+pairs = BasicLuan.pairs
+range = BasicLuan.range
+raw_equal = BasicLuan.raw_equal
+raw_get = BasicLuan.raw_get
+raw_len = BasicLuan.raw_len
+raw_set = BasicLuan.raw_set
+repr = BasicLuan.repr
+set_metatable = BasicLuan.set_metatable
+to_boolean = BasicLuan.to_boolean
+to_number = BasicLuan.to_number
+to_string = BasicLuan.to_string
+type = BasicLuan.type
+values = BasicLuan.values
--- a/core/src/luan/modules/BasicLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/BasicLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -20,48 +20,6 @@
 
 public final class BasicLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				module.put( "assert", new LuanJavaFunction(BasicLuan.class.getMethod("assert_",LuanState.class,Object.class,String.class),null) );
-				add( module, "assert_boolean", LuanState.class, Boolean.TYPE );
-				add( module, "assert_nil", LuanState.class, Object.class );
-				add( module, "assert_number", LuanState.class, Number.class );
-				add( module, "assert_string", LuanState.class, String.class );
-				add( module, "assert_table", LuanState.class, LuanTable.class );
-				add( module, "assert_integer", LuanState.class, Integer.TYPE );
-				add( module, "assert_long", LuanState.class, Long.TYPE );
-				add( module, "do_file", LuanState.class, String.class );
-				add( module, "error", LuanState.class, Object.class );
-				add( module, "get_metatable", LuanState.class, Object.class );
-				add( module, "ipairs", LuanState.class, LuanTable.class );
-				add( module, "load", LuanState.class, String.class, String.class, LuanTable.class, Boolean.class );
-				add( module, "load_file", LuanState.class, String.class, LuanTable.class );
-				add( module, "pairs", LuanState.class, LuanTable.class );
-				add( module, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class );
-				add( module, "raw_equal", Object.class, Object.class );
-				add( module, "raw_get", LuanTable.class, Object.class );
-				add( module, "raw_len", LuanState.class, Object.class );
-				add( module, "raw_set", LuanTable.class, Object.class, Object.class );
-				add( module, "repr", LuanState.class, Object.class );
-				add( module, "set_metatable", LuanTable.class, LuanTable.class );
-				add( module, "to_boolean", Object.class );
-				add( module, "to_number", Object.class, Integer.class );
-				add( module, "to_string", LuanState.class, Object.class );
-				add( module, "type", Object.class );
-				add( module, "values", new Object[0].getClass() );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(BasicLuan.class.getMethod(method,parameterTypes),null) );
-	}
-
 	public static String type(Object obj) {
 		return Luan.type(obj);
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Io.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,10 @@
+import "java:luan.modules.IoLuan"
+import "java:java.lang.System"
+
+read_console_line = IoLuan.read_console_line
+schemes = IoLuan.newSchemes()
+Uri = IoLuan.Uri
+stdin = IoLuan.defaultStdin.table()
+socket_server = IoLuan.socket_server
+stdout = IoLuan.textWriter(System.out)
+stderr = IoLuan.textWriter(System.err)
--- a/core/src/luan/modules/IoLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/IoLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -35,29 +35,10 @@
 
 public final class IoLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				add( module, "read_console_line", String.class );
-				module.put( "schemes", newSchemes() );
-				add( module, "Uri", LuanState.class, String.class, Boolean.class );
-				module.put( "stdin", stdin.table() );
-				add( module, "socket_server", Integer.TYPE );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			module.put( "stdout", textWriter(System.out) );
-			module.put( "stderr", textWriter(System.err) );
-			return module;
-		}
-	};
-
 	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
 		t.put( method, new LuanJavaFunction(IoLuan.class.getMethod(method,parameterTypes),null) );
 	}
 
-
 	public static String read_console_line(String prompt) throws IOException {
 		if( prompt==null )
 			prompt = "> ";
@@ -227,7 +208,7 @@
 			}
 		}
 
-		LuanTable table() {
+		public LuanTable table() {
 			LuanTable tbl = Luan.newTable();
 			try {
 				tbl.put( "to_string", new LuanJavaFunction(
@@ -258,7 +239,7 @@
 		}
 	}
 
-	static final LuanIn stdin = new LuanIn() {
+	public static final LuanIn defaultStdin = new LuanIn() {
 
 		@Override InputStream inputStream() {
 			return System.in;
@@ -310,7 +291,7 @@
 			return binaryWriter(new BufferedOutputStream(outputStream()));
 		}
 
-		@Override LuanTable table() {
+		@Override public LuanTable table() {
 			LuanTable tbl = super.table();
 			try {
 				tbl.put( "write", new LuanJavaFunction(
@@ -348,7 +329,7 @@
 			return new UrlCall(url).post(postS);
 		}
 
-		@Override LuanTable table() {
+		@Override public LuanTable table() {
 			LuanTable tbl = super.table();
 			try {
 				tbl.put( "post", new LuanJavaFunction(
@@ -408,7 +389,7 @@
 			return file.renameTo(new File(dest));
 		}
 
-		@Override LuanTable table() {
+		@Override public LuanTable table() {
 			LuanTable tbl = super.table();
 			try {
 				tbl.put( "name", new LuanJavaFunction(
@@ -486,26 +467,6 @@
 		if( url != null )
 			return new LuanUrl(url).table();
 
-		// try java
-		if( !isLoading )
-			return null;
-		String modName = name.replace('/','.') + "Luan.LOADER";
-//		check(luan,"classpath",modName);
-		try {
-//System.out.println("modName = "+modName);
-			final LuanFunction fn = PackageLuan.load_lib(luan,modName);  // throws exception if not found
-			LuanFunction loader = new LuanFunction() {
-				@Override public Object call(LuanState luan,Object[] args) {
-					return fn;
-				}
-			};
-			LuanTable tbl = Luan.newTable();
-			tbl.put( "loader", loader );
-			return tbl;
-		} catch(ClassNotFoundException e) {
-		} catch(NoSuchFieldException e) {
-		} catch(IllegalAccessException e) {
-		}
 		return null;
 	}
 
@@ -548,7 +509,7 @@
 		return (LuanTable)io.get("stdin");
 	}
 
-	private static LuanTable newSchemes() {
+	public static LuanTable newSchemes() {
 		LuanTable schemes = Luan.newTable();
 		try {
 			add( schemes, "file", LuanState.class, String.class, Boolean.class );
@@ -623,7 +584,7 @@
 			new PickleServer(luan,in,out).run();
 		}
 
-		@Override LuanTable table() {
+		@Override public LuanTable table() {
 			LuanTable tbl = super.table();
 			try {
 				tbl.put( "Pickle_client", new LuanJavaFunction(
--- a/core/src/luan/modules/JavaLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/JavaLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -27,21 +27,9 @@
 
 public final class JavaLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) throws LuanException {
-			LuanTable module = Luan.newTable();
-			try {
-				module.put( "class", new LuanJavaFunction(JavaLuan.class.getMethod("getClass",LuanState.class,String.class),null) );
-				add( module, "proxy", LuanState.class, Static.class, LuanTable.class, Object.class );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
 	private static boolean isLoaded(LuanState luan) {
-		return PackageLuan.loaded(luan).get("luan:Java") != null;
+//		return PackageLuan.loaded(luan).get("luan:Java") != null;
+		return true;
 	}
 
 	static LuanFunction javaLoader(LuanState luan,String modName) throws LuanException {
@@ -58,14 +46,6 @@
 		return loader;
 	}
 
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) {
-		try {
-			t.put( method, new LuanJavaFunction(JavaLuan.class.getMethod(method,parameterTypes),null) );
-		} catch(NoSuchMethodException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
 	public static Object __index(LuanState luan,Object obj,Object key) throws LuanException {
 		if( obj instanceof Static ) {
 			if( key instanceof String ) {
@@ -123,6 +103,7 @@
 			}
 		}
 //		throw luan.exception("invalid member '"+key+"' for java object: "+obj);
+//System.out.println("invalid member '"+key+"' for java object: "+obj);
 		return null;
 	}
 
@@ -138,13 +119,13 @@
 					return rtn instanceof Object[] ? Arrays.asList((Object[])rtn) : rtn;
 				} else {
 					Method method = (Method)member;
-					return new LuanJavaFunction(method,obj,true);
+					return new LuanJavaFunction(method,obj);
 				}
 			} else {
 				List<LuanJavaFunction> fns = new ArrayList<LuanJavaFunction>();
 				for( Member member : members ) {
 					Method method = (Method)member;
-					fns.add(new LuanJavaFunction(method,obj,true));
+					fns.add(new LuanJavaFunction(method,obj));
 				}
 				return new AmbiguousJavaFunction(fns);
 			}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Math.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,27 @@
+import "java:luan.modules.MathLuan"
+local JavaMath = require "java:java.lang.Math"
+
+abs = MathLuan.abs
+acos = MathLuan.acos
+asin = MathLuan.asin
+atan = MathLuan.atan
+atan2 = MathLuan.atan2
+ceil = MathLuan.ceil
+cos = MathLuan.cos
+cosh = MathLuan.cosh
+deg = MathLuan.deg
+exp = MathLuan.exp
+floor = MathLuan.floor
+log = MathLuan.log
+min = MathLuan.min
+max = MathLuan.max
+modf = MathLuan.modf
+pi = JavaMath.PI
+pow = MathLuan.pow
+rad = MathLuan.rad
+random = MathLuan.random
+sin = MathLuan.sin
+sinh = MathLuan.sinh
+sqrt = MathLuan.sqrt
+tan = MathLuan.tan
+tanh = MathLuan.tanh
--- a/core/src/luan/modules/MathLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/MathLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -10,45 +10,6 @@
 
 public final class MathLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				add( module, "abs", Double.TYPE );
-				add( module, "acos", Double.TYPE );
-				add( module, "asin", Double.TYPE );
-				add( module, "atan", Double.TYPE );
-				add( module, "atan2", Double.TYPE, Double.TYPE );
-				add( module, "ceil", Double.TYPE );
-				add( module, "cos", Double.TYPE );
-				add( module, "cosh", Double.TYPE );
-				add( module, "deg", Double.TYPE );
-				add( module, "exp", Double.TYPE );
-				add( module, "floor", Double.TYPE );
-				add( module, "log", Double.TYPE );
-				add( module, "min", Double.TYPE, new double[0].getClass() );
-				add( module, "max", Double.TYPE, new double[0].getClass() );
-				add( module, "modf", Double.TYPE );
-				module.put("pi",Math.PI);
-				add( module, "pow", Double.TYPE, Double.TYPE );
-				add( module, "rad", Double.TYPE );
-				add( module, "random", Integer.class, Integer.class );
-				add( module, "sin", Double.TYPE );
-				add( module, "sinh", Double.TYPE );
-				add( module, "sqrt", Double.TYPE );
-				add( module, "tan", Double.TYPE );
-				add( module, "tanh", Double.TYPE );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(MathLuan.class.getMethod(method,parameterTypes),null) );
-	}
-
 	public static double abs(double x) {
 		return Math.abs(x);
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Package.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,5 @@
+import "java:luan.modules.PackageLuan"
+
+loaded = PackageLuan.loaded()
+require = PackageLuan.requireFn
+load = PackageLuan.load
--- a/core/src/luan/modules/PackageLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/PackageLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -15,22 +15,6 @@
 
 public final class PackageLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			module.put( "loaded", loaded(luan) );
-			try {
-				module.put("require",requireFn);
-				add( module, "load", LuanState.class, String.class );
-//				add( module, "load_lib", LuanState.class, String.class );
-				add( module, "search", LuanState.class, String.class );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
 	public static final LuanFunction requireFn;
 	static {
 		try {
@@ -40,10 +24,6 @@
 		}
 	}
 
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(PackageLuan.class.getMethod(method,parameterTypes),null) );
-	}
-
 	public static LuanTable loaded(LuanState luan) {
 		return luan.registryTable("Package.loaded");
 	}
@@ -98,15 +78,4 @@
 		return fn==null ? null : new Object[]{fn,modName};
 	}
 
-
-	static LuanFunction load_lib(LuanState luan,String path)
-		throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException
-	{
-		int i = path.lastIndexOf('.');
-		String clsPath = path.substring(0,i);
-		String fld = path.substring(i+1);
-		Class cls = Class.forName(clsPath);
-		return (LuanFunction)cls.getField(fld).get(null);
-	}
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/String.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,18 @@
+import "java:luan.modules.StringLuan"
+
+to_binary = StringLuan.to_binary
+byte = StringLuan.byte_
+char = StringLuan.char_
+concat = StringLuan.concat
+find = StringLuan.find
+format = StringLuan.format
+gmatch = StringLuan.gmatch
+gsub = StringLuan.gsub
+len = StringLuan.len
+lower = StringLuan.lower
+match = StringLuan.match
+rep = StringLuan.rep
+reverse = StringLuan.reverse
+sub = StringLuan.sub
+trim = StringLuan.trim
+upper = StringLuan.upper
--- a/core/src/luan/modules/StringLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/StringLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -9,41 +9,11 @@
 import luan.LuanJavaFunction;
 import luan.LuanElement;
 import luan.LuanException;
+import luan.LuanMethod;
 
 
 public final class StringLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				add( module, "to_binary", String.class );
-				module.put( "byte", new LuanJavaFunction(StringLuan.class.getMethod( "byte_", String.class ),null) );
-				module.put( "char", new LuanJavaFunction(StringLuan.class.getMethod( "char_", new int[0].getClass() ),null) );
-				add( module, "concat", LuanState.class, new Object[0].getClass() );
-				add( module, "find", String.class, String.class, Integer.class, Boolean.class );
-				add( module, "format", String.class, new Object[0].getClass() );
-				add( module, "gmatch", LuanState.class, String.class, String.class );
-				add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class );
-				add( module, "len", LuanState.class, String.class );
-				add( module, "lower", LuanState.class, String.class );
-				add( module, "match", String.class, String.class, Integer.class );
-				add( module, "rep", String.class, Integer.TYPE, String.class );
-				add( module, "reverse", LuanState.class, String.class );
-				add( module, "sub", LuanState.class, String.class, Integer.TYPE, Integer.class );
-				add( module, "trim", LuanState.class, String.class );
-				add( module, "upper", LuanState.class, String.class );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(StringLuan.class.getMethod(method,parameterTypes),null) );
-	}
-
 	public static Object __index(LuanState luan,final String s,Object key) throws LuanException {
 		LuanTable mod = (LuanTable)PackageLuan.loaded(luan).get("luan:String");
 		if( mod!=null ) {
@@ -156,7 +126,7 @@
 		return m.find(start) ? new int[]{m.start()+1,m.end()} : null;
 	}
 
-	public static String[] match(String s,String pattern,Integer init) {
+	@LuanMethod public static String[] match(String s,String pattern,Integer init) {
 		int start = start(s,init,0);
 		Matcher m = Pattern.compile(pattern).matcher(s);
 		if( !m.find(start) )
@@ -190,7 +160,7 @@
 		};
 	}
 
-	public static Object[] gsub(LuanState luan,String s,String pattern,Object repl,Integer n) throws LuanException {
+	@LuanMethod public static Object[] gsub(LuanState luan,String s,String pattern,Object repl,Integer n) throws LuanException {
 		int max = n==null ? Integer.MAX_VALUE : n;
 		final Matcher m = Pattern.compile(pattern).matcher(s);
 		if( repl instanceof String ) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/modules/Table.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -0,0 +1,10 @@
+import "java:luan.modules.TableLuan"
+
+clone = TableLuan.clone
+concat = TableLuan.concat
+insert = TableLuan.insert
+pack = TableLuan.pack
+remove = TableLuan.remove
+sort = TableLuan.sort
+sub_list = TableLuan.sub_list
+unpack = TableLuan.unpack
--- a/core/src/luan/modules/TableLuan.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/TableLuan.java	Tue Dec 16 03:26:43 2014 +0000
@@ -8,37 +8,13 @@
 import luan.LuanState;
 import luan.LuanTable;
 import luan.LuanFunction;
-import luan.LuanJavaFunction;
-import luan.LuanElement;
 import luan.LuanException;
 import luan.LuanRuntimeException;
+import luan.LuanMethod;
 
 
 public final class TableLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				add( module, "clone", LuanTable.class );
-				add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class );
-				add( module, "insert", LuanTable.class, Integer.TYPE, Object.class );
-				add( module, "pack", new Object[0].getClass() );
-				add( module, "remove", LuanTable.class, Integer.TYPE );
-				add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class );
-				add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE );
-				add( module, "unpack", LuanTable.class, Integer.class, Integer.class );
-			} catch(NoSuchMethodException e) {
-				throw new RuntimeException(e);
-			}
-			return module;
-		}
-	};
-
-	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
-		t.put( method, new LuanJavaFunction(TableLuan.class.getMethod(method,parameterTypes),null) );
-	}
-
 	public static String concat(LuanState luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException {
 		int first = i==null ? 1 : i;
 		int last = j==null ? list.length() : j;
@@ -120,7 +96,7 @@
 		return tbl;
 	}
 
-	public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {
+	@LuanMethod public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {
 		int from = iFrom!=null ? iFrom : 1;
 		int to = iTo!=null ? iTo : tbl.length();
 		List<Object> list = new ArrayList<Object>();
--- a/core/src/luan/modules/Time.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/core/src/luan/modules/Time.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -2,7 +2,6 @@
 
 import "luan:String"
 import "luan:Table"
-import "luan:Java"
 import "java:java.lang.System"
 import "java:java.util.Calendar"
 import "java:java.util.Date"
--- a/logging/src/luan/modules/logging/Logging.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/logging/src/luan/modules/logging/Logging.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -1,4 +1,3 @@
-import "luan:Java"
 import "java:org.apache.log4j.Logger"
 import "java:org.apache.log4j.EnhancedPatternLayout"
 import "java:org.apache.log4j.ConsoleAppender"
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -1,5 +1,4 @@
 import "luan:Table"
-import "luan:Java"
 import "java:luan.modules.lucene.LuceneIndex"
 import "java:org.apache.lucene.index.Term"
 import "java:org.apache.lucene.search.TermQuery"
--- a/lucene/src/luan/modules/lucene/LuceneSearcher.java	Mon Dec 15 08:03:32 2014 +0000
+++ b/lucene/src/luan/modules/lucene/LuceneSearcher.java	Tue Dec 16 03:26:43 2014 +0000
@@ -28,6 +28,7 @@
 import luan.LuanJavaFunction;
 import luan.LuanException;
 import luan.LuanRuntimeException;
+import luan.LuanMethod;
 
 
 public final class LuceneSearcher {
@@ -76,7 +77,7 @@
 		}
 	}
 
-	public Object[] search( final LuanState luan, Query query, Object nObj, Sort sort ) throws LuanException, IOException {
+	@LuanMethod public Object[] search( final LuanState luan, Query query, Object nObj, Sort sort ) throws LuanException, IOException {
 		if( nObj instanceof LuanFunction ) {
 			final LuanFunction fn = (LuanFunction)nObj;
 			Collector col = new MyCollector() {
--- a/mail/src/luan/modules/mail/Mail.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/mail/src/luan/modules/mail/Mail.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -1,4 +1,3 @@
-import "luan:Java"
 import "java:java.lang.System"
 import "java:luan.modules.mail.SmtpCon"
 
--- a/web/src/luan/modules/web/Http.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/web/src/luan/modules/web/Http.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -1,4 +1,3 @@
-import "luan:Java"
 import "luan:Table"
 import "java:luan.modules.web.LuanHandler"
 
--- a/web/src/luan/modules/web/Web_server.luan	Mon Dec 15 08:03:32 2014 +0000
+++ b/web/src/luan/modules/web/Web_server.luan	Tue Dec 16 03:26:43 2014 +0000
@@ -1,4 +1,3 @@
-import "luan:Java"
 import "luan:String"
 import "luan:Io"
 import "luan:Package"