Mercurial Hosting > luan
diff core/src/luan/modules/BasicLuan.java @ 432:d9df6d6cb927
finish fixing LuanTable to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 May 2015 23:41:59 -0600 |
parents | dae264ad6a7b |
children | 75ccb4da803f |
line wrap: on
line diff
--- a/core/src/luan/modules/BasicLuan.java Sat May 02 21:12:48 2015 -0600 +++ b/core/src/luan/modules/BasicLuan.java Sat May 02 23:41:59 2015 -0600 @@ -48,32 +48,9 @@ return luan.call(fn); } - public static LuanFunction pairs(LuanState luan,final LuanTable t) throws LuanException { + public static LuanFunction pairs(final LuanState luan,final LuanTable t) throws LuanException { Utils.checkNotNull(luan,t); - Object obj = t.getHandler("__pairs"); - if( obj != null ) { - if( obj instanceof LuanFunction ) { - obj = Luan.first(luan.call((LuanFunction)obj,"__pairs",new Object[]{t})); - if( !(obj instanceof LuanFunction) ) - throw luan.exception( "metamethod __pairs should return function but returned " + Luan.type(obj) ); - return (LuanFunction)obj; - } - if( obj instanceof LuanMeta ) { - LuanMeta meta = (LuanMeta)obj; - return meta.__pairs(luan,t); - } - throw luan.exception( "invalid type of metamethod __pairs: " + Luan.type(obj) ); - } - return new LuanFunction() { - final Iterator<Map.Entry<Object,Object>> iter = t.iterator(); - - @Override public Object[] call(LuanState luan,Object[] args) { - if( !iter.hasNext() ) - return LuanFunction.NOTHING; - Map.Entry<Object,Object> entry = iter.next(); - return new Object[]{entry.getKey(),entry.getValue()}; - } - }; + return t.pairs(luan); } public static LuanFunction ipairs(LuanState luan,final LuanTable t) throws LuanException { @@ -121,7 +98,7 @@ } if( v instanceof LuanTable ) { LuanTable t = (LuanTable)v; - return t.length(); + return t.rawLength(); } throw luan.exception( "bad argument #1 to 'raw_len' (table or string expected)" ); }