diff core/src/luan/modules/BinaryLuan.java @ 302:2f8938fc518c

fix modules Binary and Html git-svn-id: https://luan-java.googlecode.com/svn/trunk@303 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 18 Dec 2014 04:56:30 +0000
parents ec016471c6eb
children 5e7450ac27f2
line wrap: on
line diff
--- a/core/src/luan/modules/BinaryLuan.java	Wed Dec 17 12:35:57 2014 +0000
+++ b/core/src/luan/modules/BinaryLuan.java	Thu Dec 18 04:56:30 2014 +0000
@@ -4,30 +4,22 @@
 import luan.LuanState;
 import luan.LuanTable;
 import luan.LuanFunction;
-import luan.LuanJavaFunction;
 import luan.LuanException;
+import luan.LuanMethod;
 
 
 public final class BinaryLuan {
 
-	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object call(LuanState luan,Object[] args) {
-			LuanTable module = Luan.newTable();
-			try {
-				add( module, "to_string", new byte[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(BinaryLuan.class.getMethod(method,parameterTypes),null) );
+	@LuanMethod public static byte[] pack(byte... bytes) {
+		return bytes;
 	}
 
-	public static String to_string(byte[] bytes) {
-		return new String(bytes);
+	@LuanMethod public static Byte[] unpack(byte[] binary) {
+		Byte[] bytes = new Byte[binary.length];
+		for( int i=0; i<binary.length; i++ ) {
+			bytes[i] = binary[i];
+		}
+		return bytes;
 	}
 
 }