Mercurial Hosting > luan
annotate core/src/luan/modules/BinaryLuan.java @ 273:073044e3ac03
fix mmake.sh and multipart mail
git-svn-id: https://luan-java.googlecode.com/svn/trunk@274 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 31 Oct 2014 18:44:11 +0000 |
parents | ec016471c6eb |
children | 2f8938fc518c |
rev | line source |
---|---|
167
4c0131c2b650
merge luan/lib into modules
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
142
diff
changeset
|
1 package luan.modules; |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 |
221
ec016471c6eb
make LuanTable an interface
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
171
diff
changeset
|
3 import luan.Luan; |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4 import luan.LuanState; |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5 import luan.LuanTable; |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
6 import luan.LuanFunction; |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
7 import luan.LuanJavaFunction; |
124
f537ff5e511d
minor cleanup
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
113
diff
changeset
|
8 import luan.LuanException; |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
9 |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
10 |
168
ebe9db183eb7
rename *Lib.java to *Luan.java
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
167
diff
changeset
|
11 public final class BinaryLuan { |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
12 |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
13 public static final LuanFunction LOADER = new LuanFunction() { |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
14 @Override public Object call(LuanState luan,Object[] args) { |
221
ec016471c6eb
make LuanTable an interface
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
171
diff
changeset
|
15 LuanTable module = Luan.newTable(); |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 try { |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
17 add( module, "to_string", new byte[0].getClass() ); |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
18 } catch(NoSuchMethodException e) { |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
19 throw new RuntimeException(e); |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
20 } |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
21 return module; |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
22 } |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
23 }; |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
24 |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
25 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
168
ebe9db183eb7
rename *Lib.java to *Luan.java
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
167
diff
changeset
|
26 t.put( method, new LuanJavaFunction(BinaryLuan.class.getMethod(method,parameterTypes),null) ); |
113
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
27 } |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
28 |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
29 public static String to_string(byte[] bytes) { |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
30 return new String(bytes); |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
31 } |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
32 |
8c706d6eb5dc
add binary type
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
33 } |