diff src/luan/lib/BasicLib.java @ 35:e51906de0f11

implement metatables git-svn-id: https://luan-java.googlecode.com/svn/trunk@36 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 18 Dec 2012 07:05:58 +0000
parents 0cdc1da466ee
children 2a35154aec14
line wrap: on
line diff
--- a/src/luan/lib/BasicLib.java	Sun Dec 16 09:23:56 2012 +0000
+++ b/src/luan/lib/BasicLib.java	Tue Dec 18 07:05:58 2012 +0000
@@ -21,17 +21,21 @@
 
 	public static void register(LuaState lua) {
 		LuaTable t = lua.global();
-		add( t, "print", new Object[0].getClass() );
-		add( t, "type", Object.class );
+		t.put( "_G", t );
+		add( t, "getmetatable", Object.class );
+		add( t, "ipairs", LuaTable.class );
 		add( t, "load", LuaState.class, String.class );
 		add( t, "loadfile", LuaState.class, String.class );
 		add( t, "pairs", LuaTable.class );
-		add( t, "ipairs", LuaTable.class );
+		add( t, "print", new Object[0].getClass() );
+		add( t, "setmetatable", LuaTable.class, LuaTable.class );
+		add( t, "type", Object.class );
+		t.put( "_VERSION", Lua.version );
 	}
 
 	private static void add(LuaTable t,String method,Class<?>... parameterTypes) {
 		try {
-			t.set( method, new LuaJavaFunction(BasicLib.class.getMethod(method,parameterTypes),null) );
+			t.put( method, new LuaJavaFunction(BasicLib.class.getMethod(method,parameterTypes),null) );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}
@@ -131,4 +135,13 @@
 			throw new RuntimeException(e);
 		}
 	}
+
+	public static LuaTable getmetatable(Object obj) {
+		return Lua.getMetatable(obj);
+	}
+
+	public static LuaTable setmetatable(LuaTable table,LuaTable metatable) {
+		table.setMetatable(metatable);
+		return table;
+	}
 }