comparison 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
comparison
equal deleted inserted replaced
34:0cdc1da466ee 35:e51906de0f11
19 19
20 public class BasicLib { 20 public class BasicLib {
21 21
22 public static void register(LuaState lua) { 22 public static void register(LuaState lua) {
23 LuaTable t = lua.global(); 23 LuaTable t = lua.global();
24 add( t, "print", new Object[0].getClass() ); 24 t.put( "_G", t );
25 add( t, "type", Object.class ); 25 add( t, "getmetatable", Object.class );
26 add( t, "ipairs", LuaTable.class );
26 add( t, "load", LuaState.class, String.class ); 27 add( t, "load", LuaState.class, String.class );
27 add( t, "loadfile", LuaState.class, String.class ); 28 add( t, "loadfile", LuaState.class, String.class );
28 add( t, "pairs", LuaTable.class ); 29 add( t, "pairs", LuaTable.class );
29 add( t, "ipairs", LuaTable.class ); 30 add( t, "print", new Object[0].getClass() );
31 add( t, "setmetatable", LuaTable.class, LuaTable.class );
32 add( t, "type", Object.class );
33 t.put( "_VERSION", Lua.version );
30 } 34 }
31 35
32 private static void add(LuaTable t,String method,Class<?>... parameterTypes) { 36 private static void add(LuaTable t,String method,Class<?>... parameterTypes) {
33 try { 37 try {
34 t.set( method, new LuaJavaFunction(BasicLib.class.getMethod(method,parameterTypes),null) ); 38 t.put( method, new LuaJavaFunction(BasicLib.class.getMethod(method,parameterTypes),null) );
35 } catch(NoSuchMethodException e) { 39 } catch(NoSuchMethodException e) {
36 throw new RuntimeException(e); 40 throw new RuntimeException(e);
37 } 41 }
38 } 42 }
39 43
129 return new LuaJavaFunction(m,ai); 133 return new LuaJavaFunction(m,ai);
130 } catch(NoSuchMethodException e) { 134 } catch(NoSuchMethodException e) {
131 throw new RuntimeException(e); 135 throw new RuntimeException(e);
132 } 136 }
133 } 137 }
138
139 public static LuaTable getmetatable(Object obj) {
140 return Lua.getMetatable(obj);
141 }
142
143 public static LuaTable setmetatable(LuaTable table,LuaTable metatable) {
144 table.setMetatable(metatable);
145 return table;
146 }
134 } 147 }