Mercurial Hosting > luan
comparison src/luan/lib/BinaryLib.java @ 113:8c706d6eb5dc
add binary type
git-svn-id: https://luan-java.googlecode.com/svn/trunk@114 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 26 May 2014 05:27:26 +0000 |
parents | |
children | f537ff5e511d |
comparison
equal
deleted
inserted
replaced
112:f5af13062b10 | 113:8c706d6eb5dc |
---|---|
1 package luan.lib; | |
2 | |
3 import luan.LuanState; | |
4 import luan.LuanTable; | |
5 import luan.LuanFunction; | |
6 import luan.LuanJavaFunction; | |
7 | |
8 | |
9 public final class BinaryLib { | |
10 | |
11 public static final String NAME = "Binary"; | |
12 | |
13 public static final LuanFunction LOADER = new LuanFunction() { | |
14 @Override public Object call(LuanState luan,Object[] args) { | |
15 LuanTable module = new LuanTable(); | |
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(BinaryLib.class.getMethod(method,parameterTypes),null) ); | |
27 } | |
28 | |
29 public static String to_string(byte[] bytes) { | |
30 return new String(bytes); | |
31 } | |
32 | |
33 } |