comparison 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
comparison
equal deleted inserted replaced
301:a6bf8ff720f8 302:2f8938fc518c
2 2
3 import luan.Luan; 3 import luan.Luan;
4 import luan.LuanState; 4 import luan.LuanState;
5 import luan.LuanTable; 5 import luan.LuanTable;
6 import luan.LuanFunction; 6 import luan.LuanFunction;
7 import luan.LuanJavaFunction;
8 import luan.LuanException; 7 import luan.LuanException;
8 import luan.LuanMethod;
9 9
10 10
11 public final class BinaryLuan { 11 public final class BinaryLuan {
12 12
13 public static final LuanFunction LOADER = new LuanFunction() { 13 @LuanMethod public static byte[] pack(byte... bytes) {
14 @Override public Object call(LuanState luan,Object[] args) { 14 return bytes;
15 LuanTable module = Luan.newTable();
16 try {
17 add( module, "to_string", new byte[0].getClass() );
18 } catch(NoSuchMethodException e) {
19 throw new RuntimeException(e);
20 }
21 return module;
22 }
23 };
24
25 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
26 t.put( method, new LuanJavaFunction(BinaryLuan.class.getMethod(method,parameterTypes),null) );
27 } 15 }
28 16
29 public static String to_string(byte[] bytes) { 17 @LuanMethod public static Byte[] unpack(byte[] binary) {
30 return new String(bytes); 18 Byte[] bytes = new Byte[binary.length];
19 for( int i=0; i<binary.length; i++ ) {
20 bytes[i] = binary[i];
21 }
22 return bytes;
31 } 23 }
32 24
33 } 25 }