Mercurial Hosting > luan
comparison src/luan/lib/MathLib.java @ 108:3c404a296995
make Package module more standard;
return _ENV by default;
add "import" statement;
git-svn-id: https://luan-java.googlecode.com/svn/trunk@109 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 03:21:54 +0000 |
parents | 7b15f56660fa |
children | f5af13062b10 |
comparison
equal
deleted
inserted
replaced
107:dbf459397217 | 108:3c404a296995 |
---|---|
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.LuanFunction; |
6 import luan.LuanLoader; | |
7 import luan.LuanJavaFunction; | 6 import luan.LuanJavaFunction; |
8 | 7 |
9 | 8 |
10 public final class MathLib { | 9 public final class MathLib { |
11 | 10 |
12 public static final String NAME = "Math"; | 11 public static final String NAME = "Math"; |
13 | 12 |
14 public static final LuanLoader LOADER = new LuanLoader() { | 13 public static final LuanFunction LOADER = new LuanFunction() { |
15 @Override protected void load(LuanState luan) { | 14 @Override public Object[] call(LuanState luan,Object[] args) { |
16 LuanTable module = new LuanTable(); | 15 LuanTable module = new LuanTable(); |
17 try { | 16 try { |
18 add( module, "abs", Double.TYPE ); | 17 add( module, "abs", Double.TYPE ); |
19 add( module, "acos", Double.TYPE ); | 18 add( module, "acos", Double.TYPE ); |
20 add( module, "asin", Double.TYPE ); | 19 add( module, "asin", Double.TYPE ); |
40 add( module, "tan", Double.TYPE ); | 39 add( module, "tan", Double.TYPE ); |
41 add( module, "tanh", Double.TYPE ); | 40 add( module, "tanh", Double.TYPE ); |
42 } catch(NoSuchMethodException e) { | 41 } catch(NoSuchMethodException e) { |
43 throw new RuntimeException(e); | 42 throw new RuntimeException(e); |
44 } | 43 } |
45 luan.loaded().put(NAME,module); | 44 return new Object[]{module}; |
46 } | 45 } |
47 }; | 46 }; |
48 | 47 |
49 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | 48 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
50 t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) ); | 49 t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) ); |