diff src/luan/lib/MathLib.java @ 55:9381b23ea9e1

various fixes git-svn-id: https://luan-java.googlecode.com/svn/trunk@56 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 04 Jan 2013 04:50:18 +0000
parents
children f86e4f77ef32
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/lib/MathLib.java	Fri Jan 04 04:50:18 2013 +0000
@@ -0,0 +1,29 @@
+package luan.lib;
+
+import luan.LuanState;
+import luan.LuanTable;
+import luan.LuanJavaFunction;
+
+
+public final class MathLib {
+
+	public static void register(LuanState luan) {
+		LuanTable module = new LuanTable();
+		LuanTable global = luan.global();
+		global.put("math",module);
+		try {
+			add( module, "floor", Double.TYPE );
+		} catch(NoSuchMethodException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
+		t.put( method, new LuanJavaFunction(MathLib.class.getMethod(method,parameterTypes),null) );
+	}
+
+	public static double floor(double x) {
+		return Math.floor(x);
+	}
+
+}