view src/luan/lib/MathLib.java @ 74:f003338d503b

improve package lib git-svn-id: https://luan-java.googlecode.com/svn/trunk@75 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 13 Feb 2013 06:27:56 +0000
parents f86e4f77ef32
children 4bf3d0c0b6b9
line wrap: on
line source

package luan.lib;

import luan.LuanState;
import luan.LuanTable;
import luan.LuanFunction;
import luan.LuanJavaFunction;


public final class MathLib {

	public static final String NAME = "math";

	public static final LuanFunction LOADER = new LuanFunction() {
		public Object[] call(LuanState luan,Object[] args) {
			LuanTable module = new LuanTable();
			LuanTable global = luan.global;
			try {
				add( module, "floor", Double.TYPE );
			} catch(NoSuchMethodException e) {
				throw new RuntimeException(e);
			}
			return new Object[]{module};
		}
	};

	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);
	}

}