Mercurial Hosting > luan
comparison src/luan/modules/BinaryLib.java @ 167:4c0131c2b650
merge luan/lib into modules
git-svn-id: https://luan-java.googlecode.com/svn/trunk@168 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 22 Jun 2014 04:28:32 +0000 |
parents | src/luan/lib/BinaryLib.java@05f8c21160ef |
children |
comparison
equal
deleted
inserted
replaced
166:4eaee12f6c65 | 167:4c0131c2b650 |
---|---|
1 package luan.modules; | |
2 | |
3 import luan.LuanState; | |
4 import luan.LuanTable; | |
5 import luan.LuanFunction; | |
6 import luan.LuanJavaFunction; | |
7 import luan.LuanException; | |
8 | |
9 | |
10 public final class BinaryLib { | |
11 | |
12 public static final LuanFunction LOADER = new LuanFunction() { | |
13 @Override public Object call(LuanState luan,Object[] args) { | |
14 LuanTable module = new LuanTable(); | |
15 try { | |
16 add( module, "to_string", new byte[0].getClass() ); | |
17 } catch(NoSuchMethodException e) { | |
18 throw new RuntimeException(e); | |
19 } | |
20 return module; | |
21 } | |
22 }; | |
23 | |
24 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | |
25 t.put( method, new LuanJavaFunction(BinaryLib.class.getMethod(method,parameterTypes),null) ); | |
26 } | |
27 | |
28 public static String to_string(byte[] bytes) { | |
29 return new String(bytes); | |
30 } | |
31 | |
32 } |