Mercurial Hosting > luan
comparison core/src/luan/modules/BasicLuan.java @ 413:8937263f59f6
add __pairs;
add back HttpServicer.get_parameter_values;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Apr 2015 19:01:18 -0600 |
parents | d55e873e1f0d |
children | 8fbb961aabd5 |
comparison
equal
deleted
inserted
replaced
412:094f37c5e6f9 | 413:8937263f59f6 |
---|---|
14 import luan.LuanJavaFunction; | 14 import luan.LuanJavaFunction; |
15 import luan.LuanException; | 15 import luan.LuanException; |
16 import luan.LuanSource; | 16 import luan.LuanSource; |
17 import luan.LuanElement; | 17 import luan.LuanElement; |
18 import luan.LuanMethod; | 18 import luan.LuanMethod; |
19 import luan.LuanMeta; | |
19 import luan.impl.LuanCompiler; | 20 import luan.impl.LuanCompiler; |
20 | 21 |
21 | 22 |
22 public final class BasicLuan { | 23 public final class BasicLuan { |
23 | 24 |
47 return luan.call(fn); | 48 return luan.call(fn); |
48 } | 49 } |
49 | 50 |
50 public static LuanFunction pairs(LuanState luan,final LuanTable t) throws LuanException { | 51 public static LuanFunction pairs(LuanState luan,final LuanTable t) throws LuanException { |
51 Utils.checkNotNull(luan,t); | 52 Utils.checkNotNull(luan,t); |
52 return new LuanFunction() { | 53 Object obj = luan.getHandler("__pairs",t); |
53 Iterator<Map.Entry<Object,Object>> iter = t.iterator(); | 54 if( obj != null ) { |
55 if( obj instanceof LuanFunction ) { | |
56 obj = Luan.first(luan.call((LuanFunction)obj,"__pairs",new Object[]{t})); | |
57 if( !(obj instanceof LuanFunction) ) | |
58 throw luan.exception( "metamethod __pairs should return function but returned " + Luan.type(obj) ); | |
59 return (LuanFunction)obj; | |
60 } | |
61 if( obj instanceof LuanMeta ) { | |
62 LuanMeta meta = (LuanMeta)obj; | |
63 return meta.__pairs(luan,t); | |
64 } | |
65 throw luan.exception( "invalid type of metamethod __pairs: " + Luan.type(obj) ); | |
66 } | |
67 return new LuanFunction() { | |
68 final Iterator<Map.Entry<Object,Object>> iter = t.iterator(); | |
54 | 69 |
55 @Override public Object[] call(LuanState luan,Object[] args) { | 70 @Override public Object[] call(LuanState luan,Object[] args) { |
56 if( !iter.hasNext() ) | 71 if( !iter.hasNext() ) |
57 return LuanFunction.NOTHING; | 72 return LuanFunction.NOTHING; |
58 Map.Entry<Object,Object> entry = iter.next(); | 73 Map.Entry<Object,Object> entry = iter.next(); |