view src/luan/lib/BasicLib.java @ 4:24fd6381caca

add to interp git-svn-id: https://luan-java.googlecode.com/svn/trunk@5 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 18 Nov 2012 04:18:15 +0000
parents 7a2cdbc5767f
children 8217d8485715
line wrap: on
line source

package luan.lib;

import luan.Lua;
import luan.LuaTable;
import luan.LuaJavaFunction;


public class BasicLib {

	public static void register(LuaTable t) {
		add( t, "print", new Object[0].getClass() );
		add( t, "type", Object.class );
	}

	private static void add(LuaTable t,String method,Class<?>... parameterTypes) {
		try {
			t.set( method, new LuaJavaFunction(BasicLib.class.getMethod(method,parameterTypes),null) );
		} catch(NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}

	public static void print(Object... args) {
		for( int i=0; i<args.length; i++ ) {
			if( i > 0 )
				System.out.print('\t');
			System.out.print( Lua.checkString(args[i]) );
		}
		System.out.println();
	}

	public static String type(Object obj) {
		return Lua.type(obj);
	}

}