Mercurial Hosting > luan
comparison src/luan/lib/MathLib.java @ 73:f86e4f77ef32
add package module
git-svn-id: https://luan-java.googlecode.com/svn/trunk@74 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 12 Feb 2013 09:46:45 +0000 |
parents | 9381b23ea9e1 |
children | f003338d503b |
comparison
equal
deleted
inserted
replaced
72:cd9dbd7477ca | 73:f86e4f77ef32 |
---|---|
1 package luan.lib; | 1 package luan.lib; |
2 | 2 |
3 import luan.LuanState; | 3 import luan.LuanState; |
4 import luan.LuanTable; | 4 import luan.LuanTable; |
5 import luan.LuanFunction; | |
5 import luan.LuanJavaFunction; | 6 import luan.LuanJavaFunction; |
6 | 7 |
7 | 8 |
8 public final class MathLib { | 9 public final class MathLib { |
9 | 10 |
10 public static void register(LuanState luan) { | 11 public static final String NAME = "math"; |
11 LuanTable module = new LuanTable(); | 12 |
12 LuanTable global = luan.global(); | 13 public static final LuanFunction LOADER = new LuanFunction() { |
13 global.put("math",module); | 14 public Object[] call(LuanState luan,Object[] args) { |
14 try { | 15 LuanTable module = new LuanTable(); |
15 add( module, "floor", Double.TYPE ); | 16 LuanTable global = luan.global; |
16 } catch(NoSuchMethodException e) { | 17 global.put(NAME,module); |
17 throw new RuntimeException(e); | 18 try { |
19 add( module, "floor", Double.TYPE ); | |
20 } catch(NoSuchMethodException e) { | |
21 throw new RuntimeException(e); | |
22 } | |
23 return LuanFunction.EMPTY_RTN; | |
18 } | 24 } |
19 } | 25 }; |
20 | 26 |
21 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | 27 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
22 t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) ); | 28 t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) ); |
23 } | 29 } |
24 | 30 |