Mercurial Hosting > luan
diff src/luan/LuanTable.java @ 1335:e0cf0d108a77
major cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 03:10:45 -0700 |
parents | 25746915a241 |
children | 2024d23ddd64 |
line wrap: on
line diff
--- a/src/luan/LuanTable.java Tue Feb 12 22:53:57 2019 -0700 +++ b/src/luan/LuanTable.java Thu Feb 14 03:10:45 2019 -0700 @@ -73,7 +73,7 @@ clone.security = security; switch( cloner.type ) { case COMPLETE: - deepenClone(clone,cloner); + completeClone(clone,cloner); return; case INCREMENTAL: clone.cloner = cloner; @@ -87,12 +87,17 @@ private void check() { if( cloner != null ) { - deepenClone(this,cloner); + completeClone(this,cloner); cloner = null; } } - private void deepenClone(LuanTable clone,LuanCloner cloner) { + public Luan luan() { + check(); + return luan; + } + + private void completeClone(LuanTable clone,LuanCloner cloner) { clone.luan = (Luan)cloner.clone(luan); if( map != null ) { Map newMap = newMap(); @@ -132,7 +137,7 @@ if( h == null ) return rawToString(); LuanFunction fn = Luan.checkFunction(h); - return Luan.checkString( Luan.first( fn.call(luan,new Object[]{this}) ) ); + return Luan.checkString( Luan.first( fn.call(this) ) ); } public String rawToString() { @@ -148,7 +153,7 @@ return null; if( h instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)h; - return Luan.first(fn.call(luan,new Object[]{this,key})); + return Luan.first(fn.call(this,key)); } return luan.index(h,key); } @@ -180,7 +185,7 @@ } if( h instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)h; - fn.call(luan,new Object[]{this,key,value}); + fn.call(this,key,value); return; } if( h instanceof LuanTable ) { @@ -286,7 +291,7 @@ Object h = getHandler("__len"); if( h != null ) { LuanFunction fn = Luan.checkFunction(h); - return (Integer)Luan.first(fn.call(luan,new Object[]{this})); + return (Integer)Luan.first(fn.call(this)); } return rawLength(); } @@ -323,7 +328,7 @@ private Map.Entry<Object,Object> getNext() { try { - Object obj = fn.call(luan); + Object obj = fn.call(); if( obj==null ) return null; Object[] a = (Object[])obj; @@ -356,7 +361,7 @@ if( h != null ) { if( h instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)h; - Object obj = Luan.first(fn.call(luan,new Object[]{this})); + Object obj = Luan.first(fn.call(this)); if( !(obj instanceof LuanFunction) ) throw new LuanException( "metamethod __pairs should return function but returned " + Luan.type(obj) ); return (LuanFunction)obj; @@ -367,10 +372,10 @@ } private LuanFunction rawPairs() { - return new LuanFunction() { + return new LuanFunction(false) { // ??? final Iterator<Map.Entry> iter = rawIterator(); - @Override public Object[] call(Luan luan,Object[] args) { + @Override public Object[] call(Object[] args) { if( !iter.hasNext() ) return LuanFunction.NOTHING; Map.Entry<Object,Object> entry = iter.next(); @@ -517,14 +522,13 @@ Object h = getHandler("__gc"); if( h != null ) { LuanFunction fn = Luan.checkFunction(h); - fn.call(luan,new Object[]{this}); + fn.call(this); } super.finalize(); } - public Object call(String fnName,Object... args) throws LuanException { - LuanFunction fn = (LuanFunction)get(fnName); - return fn.call(luan,args); + public LuanFunction fn(String fnName) throws LuanException { + return (LuanFunction)get(fnName); } public static void setSecurity(LuanTable tbl,String security) {