diff src/luan/lib/BasicLib.java @ 2:4da26b11d12a

start interp git-svn-id: https://luan-java.googlecode.com/svn/trunk@3 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 14 Nov 2012 08:53:25 +0000
parents
children 7a2cdbc5767f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/lib/BasicLib.java	Wed Nov 14 08:53:25 2012 +0000
@@ -0,0 +1,31 @@
+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() );
+	}
+
+	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.toString(args[i]) );
+		}
+		System.out.println();
+	}
+
+}